Kevin,

Thanks for the reply.

I am struggling to pass back the output to generate an alert for each line 
returned from the powershell script e.g.

[cid:[email protected]]

An alert generated for The certificate name and the Expiry Date?

Thanks in advance.

Ps. It is SCOM 2007 R2



Peter Hakesley | Monitoring & Automation Technical Lead Engineer, Data Centre 
Services

t: +44(0)845 155 6556 ext: 4006
e: [email protected] | w: www.scc.com<http://www.scc.com/>
a: SCC, CV1, Cole Valley, 20 Westwood Avenue, Tyseley, Birmingham B11 3RZ



From: [email protected] [mailto:[email protected]] On 
Behalf Of Kevin Holman
Sent: 27 January 2015 16:23
To: [email protected]
Subject: [msmom] RE: M Authoring Help

Hi Peter -

What part are you struggling with?

If you just want to run a generic powershell script, you would use a Timed 
Script rule.  However, the timed script rule in the UI/Console under Authoring 
only supports VBscripts.


The "old school" way would be to run a timed command rule, and pass 
powershell.exe as the command and the script path as a parameter:
http://www.systemcentercentral.com/forums-archive/topic/run-powershell-script-as-a-timed-command-rule/
https://social.technet.microsoft.com/Forums/en-US/6693c59d-3e87-46c1-ba6d-ba82c663148e/scom-2012-rule-powershell-script-launch-a-script-on-schedule?forum=operationsmanagerauthoring


The "right" way is to use the 2007R2 authoring console, or VSAE, and create a 
new rule that leverages the scheduler datasource, a filter on the schedule for 
a condition detection, and a PowerShell write action using 
Microsoft.Windows.PowerShellWriteAction:

https://msdn.microsoft.com/en-us/library/hh367527.aspx

I have a REALLY simple example of how to do this here:
http://blogs.technet.com/b/kevinholman/archive/2014/01/24/targeting-workflows-to-resource-pools.aspx




From: [email protected]<mailto:[email protected]> 
[mailto:[email protected]] On Behalf Of Pete Hakesley
Sent: Tuesday, January 27, 2015 1:59 AM
To: MSMOM ([email protected]<mailto:[email protected]>)
Subject: [msmom] M Authoring Help

Hi,

I have created a Powershell script to check for all certificates which are to 
expire within 45 and 90 days on any machine it is run against. It creates 
application log entries for each certificate about to expire in the specified 
date ranges

I am struggling to put this into a management pack.


Powershell script:
$strWarningDays = 90
$strErrorDays=45

$strLogSourceExists = Get-Eventlog -logName Application | select-object Source 
-Unique
if (! $strLogSourceExists)
{
  New-Eventlog -LogName Application -Source CertExpiry45Days
  New-Eventlog -LogName Application -Source CertExpiry90Days
}

$strCerts45 = @(get-childitem -Path cert:\* -Recurse | where { $_.notafter -le 
(get-date).AddDays($strErrorDays) -AND $_.notafter -gt (get-date)} | select 
subject,thumbprint,friendlyname,NotAfter)
$strCerts90 = @(get-childitem -Path cert:\* -Recurse | where { $_.notafter -le 
(get-date).AddDays($StrWarningDays) -AND $_.notafter -gt (get-date)} | select 
subject,thumbprint,friendlyname,NotAfter)

foreach($strCertificate in $strCerts45)
{
  write-Eventlog -LogName Application -Source "CertExpiry45Days" -EntryType 
Error -EventId 100 -Message $StrCertificate
}
$str90Days = @(Compare-Object $strCerts45 $strCerts90).InputObject
foreach($str90DayCert in $str90Days)
{
   write-Eventlog -LogName Application -Source "CertExpiry90Days" -EntryType 
Warning -EventId 100 -Message $Str90DayCert
}

Now I want to put this into a management pack does anyone have some examples so 
I can distribute this out to one of my hosted customers? thks



Peter Hakesley | Monitoring & Automation Technical Lead Engineer, Data Centre 
Services

t: +44(0)845 155 6556 ext: 4006
e: [email protected]<mailto:[email protected]> | w: 
www.scc.com<http://www.scc.com/>
a: SCC, CV1, Cole Valley, 20 Westwood Avenue, Tyseley, Birmingham B11 3RZ








Reply via email to