Skip to content

Instantly share code, notes, and snippets.

@psitem
Created February 15, 2025 14:48
Show Gist options
  • Save psitem/a0bd07aaa61fa1665819d47b374d8b82 to your computer and use it in GitHub Desktop.
Save psitem/a0bd07aaa61fa1665819d47b374d8b82 to your computer and use it in GitHub Desktop.
Output total disk read/write activity in MB/s
Get-Counter -Counter "\LogicalDisk(_Total)\Disk Read Bytes/sec","\LogicalDisk(_Total)\Disk Write Bytes/sec" -Continuous -SampleInterval 1 | ForEach-Object {
[PSCustomObject]@{
Time = (get-date $_.Timestamp -Format u).replace("Z", "")
Read = [math]::round($_.CounterSamples[0].CookedValue /1Mb, 0)
Write = [math]::round($_.CounterSamples[1].CookedValue /1Mb, 0)
}
}
@psitem
Copy link
Author

psitem commented Feb 15, 2025

Sample output:

Time                Read Write
----                ---- -----
2025-02-15 09:44:28   58    58
2025-02-15 09:44:29   80    80
2025-02-15 09:44:30   70    70
2025-02-15 09:44:31   69    70

@psitem
Copy link
Author

psitem commented Feb 15, 2025

This is another variation I use on a system with dozens of disks where I want to see the aggregate disk activity along with the activity on individual disks, ignoring disks with < 1KB/s.

$first=$true ; Get-Counter -Counter "\LogicalDisk(*)\Disk Read Bytes/sec","\LogicalDisk(*)\Disk Write Bytes/sec"  -Continuous -SampleInterval 1 | ForEach-Object {
    $dt = ( get-date $_.Timestamp -Format u ).replace( "Z", "" )
    $cs = ( $_.CounterSamples | Sort-Object InstanceName,Path )

    for ( $i=0; $i -lt $cs.count; $i+=2 ) {
        if ( ( $first -eq $true ) -or ( ( $cs[$i].CookedValue -gt 1024 ) -or ( $cs[$i+1].CookedValue -gt 1024 ) ) ) {
            [PSCustomObject]@{
            Time      = $dt
            Instance  = $cs[$i].InstanceName
            Read      = [math]::round( $cs[$i].CookedValue /1Mb, 0 )
            Write     = [math]::round( $cs[$i+1].CookedValue /1Mb, 0 )
           }
        }
    }
    $first = $false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment