Advertisement
guyrleech

Get perfmon data as single objects

Aug 6th, 2024 (edited)
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.17 KB | Software | 0 0
  1. ## 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
  2. ## using ordered dictionary to add counters so can be converted to pscustomobject and so time stamp can be 1st property/column
  3. ## note replace of leading \\ on counter names and then replacing \ with newline to reduce the width needed for display by Format-Table
  4. ## use Get-Counter -ListSet to show what counters are available
  5.  
  6. [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