Thursday, January 26, 2012

[Powershell] Get Rules informations and Monitors informations for a spécified MP in SCOM

Here is a short powershell function that create 2 CVS files. One with Rules informations and an other one for Monitors information for a specified MP :
  1. Function RetrieveIDs()
  2. {
  3. Param ([String] $MPName, [String]$Path)
  4. If ($Path -eq "") { $Path=("C:\Temp") }
  5. $MonitorsFile = $Path + "\MonitorsIds.csv"
  6. $RulesFile = $Path + "\RulesIds.csv"
  7. "Files MonitorsIds.csv & RulesIds.csv will be generated in : " + $Path
  8. If ($MPName -eq "") { $MPName=(Read-Host "Enter a Management Pack Name ") }
  9. $mp=Get-ManagementPack | where {$_.name -eq $MPName}
  10. if ($mp -eq $null) {
  11.       "The ManagementPack you have put in argument is incorrect or not found"
  12.       "Here is a list of available MP:"
  13.       Get-ManagementPack | sort -property Name | ft Name
  14.       break
  15.       }
  16. $mp.Getmonitors() | select DisplayName, XMLTag,Category,Name,id, @{name="Description";expression={foreach-object {$_.Description -replace "\n","-"}}}  | export-csv -noTypeInformation -path $MonitorsFile
  17. $mp.Getrules() | select DisplayName,  XMLTag,Category,Name,id, @{name="Description";expression={foreach-object {$_.Description -replace "\n","-"}}} | export-csv -noTypeInformation -path $RulesFile
  18. }
3 ways to use the function :
  •  Just launch the command with no parameter:
PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::> retrieveIDs

No cvs files will be created since no MP Name is given. The output of the script will be the list of available MP.

  • Launch the command with 1 parameter that should be a MP Name:
PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::> retrieveIDs MyMPName

The cvs files MonitorsIds.csv & RulesIds.csv will be created in the default folder that is C:\Temp. You will retrieve information for the rules and monitors for the MyMPName MP.


  • Launch the command with 2 parameter that should be a MP Name and the path where to create the files :
PS Microsoft.EnterpriseManagement.OperationsManager.Client\OperationsManagerMonitoring::> retrieveIDs MyMPName C:\MyPath

The cvs files MonitorsIds.csv & RulesIds.csv will be created in the C:\MyPath folder. You will retrieve information for the rules and monitors for the MyMPName MP.

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

No comments:

Post a Comment