Powershell script to pull out performance objects, counters and sample count for a specific counter collected by SCOM

The below powershell script extracts the number of samples of a specific performance object and counter in the last 24 hours.

This information can be used to check if the performance data is being collected and can also be input into a run-book in SCORCH to further troubleshoot the counts that comes out to 0.

For this script the objectname for the performance data is ‘Cluster Shared Volume’ and the counter is ‘Free space / Percent’

$managementServer=”management server name here”

import-module OperationsManager

try {$mg = New-Object Microsoft.EnterpriseManagement.ManagementGroup($managementServer)}

catch {

“Could not connect to management server $managementServer”

exit(0)

}

$starttime = [datetime]::today.addhours(-24)

$endtime = [datetime]::today.adddays(1)

$mpdc = “ObjectName = ‘Cluster Shared Volume’ and CounterName = ‘Free space / Percent'”

$mpds = $mg.GetMonitoringPerformanceDataReader($mpdc)

while ($mpds.read())

{

$perfdata = $mpds.getmonitoringperformancedata()

#write-host $perfdata.count

$valuereader = $perfdata.getvalues($starttime, $endtime)

$displayname = $perfdata.monitoringobjectdisplayname.tostring()

$path = $perfdata.monitoringobjectpath.tostring()

$count = $valuereader.count.tostring()

write-host “$path, $displayname, $count”

# write-host $perfdata.monitoringobjectpath

}