15 mars 2011

What management packs are applied to your SCOM agents

What management packs are applied to your agents ? It is something not really easy.
For each agent you retreive all objects discovered related to the agent, then you can retreive all the classes of thoses objects, so you are able to retreive the management applied to the Agent

$agent=Get-Agent
$max=$agent.count
$t=0
"Retreiving all Classes"
$AllMP = New-Object System.Collections.Hashtable

$servers=@()
$record = New-Object system.object
$record  | add-Member -memberType noteProperty -name "Server" -Value "NA"
Get-ManagementPack | where  {$_.sealed -eq $TRUE } | sort -Property Name |foreach {
    $mpname=$_.Name
    $record | add-Member -memberType noteProperty -name $mpname -Value "No"
    $mpname
    $_.GetClasses() |  foreach { $AllMP[$_.Name.tostring()]=$mpname }
  
    }
$servers+=$record

$agent |% {
    write-progress -activity "Dealing with"  -status "% Complete:" -percentcomplete ($t*100/$max)
    $record = New-Object system.object
    $record | add-Member -memberType noteProperty -name "Server" -Value $_.PrincipalName
    $_.HostComputer.GetRelatedMonitoringObjects() | % {
        $record | add-Member -memberType noteProperty -Force -name $AllMP[$_.GetLeastDerivedNonAbstractMonitoringClass().Name] -Value "Yes"
        }
    $servers+=$record
    $t++
}
$servers

Get all alerts from a management pack

For example, In SCOM if you want to retreive all alerts from a management packs, you can do something like this
$crit=""
$count=0
get-managementpack | ? { $_.Name -match "Citrix"} | % { $_.getclasses() | % {

    If ($count -eq 0) {$crit= "MonitoringClassId = '"+$_.id.tostring()+"'"; $count++}
    else { $crit= $crit + "OR MonitoringClassId = '"+$_.id.tostring()+"'" }
 }}
get-alert -criteria $crit

This powershell script retreive Citrix alerts...