Get Network Utilization by Joel Bennett 20 months ago (modification of post by Jason Ochoa view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1900"></script>download | new post
get utilization from all network interfaces
- $counters = @()
- foreach ($inst in (new-object System.Diagnostics.PerformanceCounterCategory("network interface")).GetInstanceNames()){
- $cur = New-Object system.Diagnostics.PerformanceCounter('Network Interface','Bytes Total/sec', $inst)
- $max = New-Object system.Diagnostics.PerformanceCounter('Network Interface','Current Bandwidth', $inst)
- $cur.NextValue() | Out-Null
- $max.NextValue() | Out-Null
- $counters += @{"Throughput"=$cur;"Bandwidth"=$max;"Name"=$inst}
- }
- sleep 2
- foreach($counter in $counters) {
- $curnum = $counter.Throughput.NextValue()
- $maxnum = $counter.Bandwidth.NextValue()
- New-Object PSObject -Property @{"Util"=$((( $curnum * 8 ) / $maxnum ) * 100);"Name"=$counter.Name}
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository