Thursday, January 31, 2013

[OpsMgr 2007 R2][OpsMgr 2012] Get Rule/Monitor full information from Rule/Monitor name - Powershell script



Today, I've had a request to retrieve all informations for a rule that was generating too much alerts. The rule was give, by it's name and the name was not really user friendly : _08C092E8_FD6F_48b2_BA1E_473C3B84A2F3_.RaiseAlert

Thanks to the Exchange Server 2010 Management pack developper team :)

So I've create a short powershell function to add to my powershell profile :

  1. Function RuleInfo  ([string]$RuleName)
  2. {
  3. get-rule | where {$_.Name -eq $RuleName} | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category, Target, ConfirmDelivery, Remotable, Priority, DiscardLevel, ConditionDetection, DataSourceCollection, WriteActionCollection, Id, Description, Comment, Status, LastModified, TimeAdded
  4. }
Then I've launch it in my powershell console using the line :

RuleInfo  _08C092E8_FD6F_48b2_BA1E_473C3B84A2F3_.RaiseAlert

Result is like :



 Well done ! :)


I've also created the same function for monitors :

  1. Function MonitorInfo  ([string]$MonitorName)
  2. {
  3. get-monitor | where {$_.Name -eq $MonitorName} | select-object @{Name="MP";Expression={ foreach-object {$_.GetManagementPack().DisplayName }}}, @{Name="MP Version";Expression={ foreach-object {$_.GetManagementPack().Version }}}, Name, DisplayName, XmlTag, Enabled, Category, Configuration, Id, ConfirmDelivery, OperationalStateCollection, Target, ParentMonitorID, Remotable, Priority, RunAs, AlertSettings, Accessibility, Description, LanguageCode, Comment, Status, LastModified, TimeAdded
  4. }
Have fun !

This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment