Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## get perfmon counters, in this example from a remote machine, and create as 1 object per sample period where each sample contains 3 counters so if we just output that , it would be 3 lines per sample whereas this method outputs 1 line
- ## using ordered dictionary to add counters so can be converted to pscustomobject and so time stamp can be 1st property/column
- ## note replace of leading \\ on counter names and then replacing \ with newline to reduce the width needed for display by Format-Table
- ## use Get-Counter -ListSet to show what counters are available
- [string[]]$counters=@( '\PhysicalDisk(* C:)\% disk time' , "\Memory\Available MBytes","\Processor(_total)\% Processor Time","\Hyper-v Hypervisor Logical Processor(_total)\% total run time" ) ;$r=[System.Collections.Specialized.OrderedDictionary]::new();Get-Counter -MaxSamples 120 -SampleInterval 30 -ComputerName grl-dc10 -Counter $counters|select -ExpandProperty CounterSamples|% { if( $r.Count -ge $counters.Count ) { $r.Insert( 0 , 'Time' , $_.TimeStamp.ToString('T') ) ; [pscustomobject]$r ; $r.Clear() } ; $r.Add( ( $_.Path -replace '^\\\\' -replace '\(_total\)' , 's' -replace '\\' , "`n" ), $_.CookedValue ) }|format-table
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement