Get last value sampled by performance collection rule

I took some time today to find something new to add to my Command Shell examples table.  I thought this one was kind of neat.  For those of you who like to use the CLI, this is an alternative to get quick info as opposed to using the console.

This example in particular returns the LogicalDisk \ % Free Space counter sample for all J: drives.  Just replace the red parameters to return values of any counter that is being collected by SCOM.  Beware of word wrap, as this is a one-liner.  Also, those are all single quotes in the criteria selection.

 

Get-PerformanceCounter -Criteria 'ObjectName = ''LogicalDisk'' and CounterName = ''% Free Space'' and InstanceName = ''J:''' | Select MonitoringObjectPath, MonitoringObjectDisplayName, @{Name="Value";Expression={Foreach-Object {$_.GetValues((Get-Date).AddDays(-1),(Get-Date)) | Select -Last 1}}}

 

Command Shell Main Menu