Skip to content

Instantly share code, notes, and snippets.

@aaronpmiller
Created March 24, 2015 17:48
Show Gist options
  • Save aaronpmiller/4cd690cfbca7e6d0bca7 to your computer and use it in GitHub Desktop.
Save aaronpmiller/4cd690cfbca7e6d0bca7 to your computer and use it in GitHub Desktop.
$counters = (Get-Counter -ListSet Process).Counter | ? {$_ -like "*Bytes"} | % {$_.Replace('*','Powershell*')}
[string[]]$CounterNames = $counters | % {$_.split('\')[-1].ToLower()}
[string[]]$itemProperties = @()
$itemProperties += 'Timestamp'
$itemProperties += $CounterNames | ForEach-Object {$_.Replace('bytes','(MB)')}
$blankItem = '' | Select $itemProperties
Get-Counter -Counter $counters -SampleInterval 2 -Continuous| % {
$item = $blankItem
$item.Timestamp = $_.Timestamp
$groups = $_.countersamples | Group-Object {Split-Path $_.Path -Leaf}
foreach ($CounterName in $CounterNames) {
$item.$($CounterName.Replace('bytes','(MB)')) = (($groups | Where-Object {$_.Name -eq $CounterName}).Group | Measure-Object -Sum CookedValue).Sum/1MB
}
$item
} | Out-GridView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment