Skip to content

Instantly share code, notes, and snippets.

@joegasper
Last active August 26, 2016 04:24
Show Gist options
  • Save joegasper/c8c60a9caf41a1d2ce753710bd7a7fe6 to your computer and use it in GitHub Desktop.
Save joegasper/c8c60a9caf41a1d2ce753710bd7a7fe6 to your computer and use it in GitHub Desktop.
Collect performance counters across a list of systems
$counters = @('\Paging File(_total)\% Usage','\Paging File(_total)\% Usage Peak','\Memory\Available MBytes','\Memory\% Committed Bytes In Use','\System\System Up Time')
$servers = @()
#assumes your systems are named 'myexchbox01', 'myexchbox02', etc. and you have 20 of them
1..20 | % { $servers += 'myexchbox' + '{0:D2}' -f $_ }
$Path = 'C:\Work\Perf\'
$filename = 'Exchange'
$delay = 1
$count = 1
$sequence = 1
$testrun = Get-Date -Format yyyy-MM-dd
if ($obj) {Remove-Variable obj} #in case you run it again...
Foreach ($server in $servers) {
$metrics = Get-Counter -ComputerName $server -Counter $counters -SampleInterval $delay -MaxSamples $count
foreach($metric in $metrics)
{
$obj += $metric.CounterSamples | Select-Object -Property Path, CookedValue, Timestamp;
# add these columns as data
$obj | Add-Member -MemberType NoteProperty -Name Sequence -Value $sequence -Force;
$obj | Add-Member -MemberType NoteProperty -Name LoadTest -Value $testrun -Force;
$obj | Add-Member -MemberType NoteProperty -Name Computer -Value $server -Force;
$sequence += 1;
}
}
$obj | Export-Csv -Path "$path$filename.$testrun.$sequence.csv" -NoTypeInformation;
#bonus - list counters in a specific category
#Get-Counter -ListSet system | select -ExpandProperty counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment