Menu Close

Getting Monitor State Change Events via PowerShell



This is a script example on how to get statechangeevents from monitor context using PowerShell.  This example uses a URL transaction monitor, but you can change this to any class/classinstance.


#Set arrays to empty $Monitor = @() $MonitorColl = @() $States = @() #Get Web Transaction URL Class $URLClass = Get-SCOMClass -Name 'Microsoft.SystemCenter.WebApplication.Perspective' #Get an array of matching specific instances of URL Class $URLInstances = $URLClass | Get-SCOMClassInstance | where {$_.displayname -eq "Bing URL Transaction"} #Loop through each URL instance ForEach ($UrlTest in $URLInstances) { #Set the monitor collection to empty and create the collection to contain monitors $MonitorColl = @() $MonitorColl = New-Object "System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]" #Get specific monitors matching a displayname for this instance of URLtest ONLY $Monitor = Get-SCOMMonitor -Instance $UrlTest -Recurse | where {$_.DisplayName -eq "Content Match"} #Add this monitor to a collection $MonitorColl.Add($Monitor) #Get the state associated with this specific monitor $State=$UrlTest.getmonitoringstates($MonitorColl) #Add each state found in the loop to an array to be used later $States += $State } #get any statechangeevents for each item in the array $States[0].getmonitoringstatechangeevents() $States[1].getmonitoringstatechangeevents()

Leave a Reply

Your email address will not be published.