Today we look at get-counter which you should have a fiddle with if you get the chance. It does a lot more than what we've used it for here. But this may help you get the gist of running performance counters in powershell.
$disks = Get-WmiObject win32_logicaldisk | Where-Object {$_.DriveType -eq 3} | select DeviceID
$report = @() $i=1 foreach ($disk in $disks) { Write-Progress -Activity "Mesuring disk performance" -Status $disk.DeviceID -PercentComplete (($i/$disks.Count)*100) $temp = "" | select Disk, Read, Write $temp.disk = $disk.deviceid $counter = "\LogicalDisk(" + ($disk.deviceid) + ")\Avg. Disk sec/Read" $temp.read = ((Get-Counter -Counter $counter).CounterSamples.cookedvalue)*1000 $counter = "\LogicalDisk(" + ($disk.deviceid) + ")\Avg. Disk sec/Write" $temp.write = ((Get-Counter -Counter $counter).CounterSamples.cookedvalue)*1000 $report += $temp $i++ } $report |
We've included the now ubiquitous write-progess to give a useful progress indicator. As well as the old $temp="" | select which sets up a hash table for us to dump data into.
No comments:
Post a Comment