# encoding: ascii
# api: powershell
# title: Get Network Utilization
# description: get utilization from all network interfaces
# version: 0.1
# author: Jason Ochoa
# license: CC0
# x-poshcode-id: 1900
# x-derived-from-id: 6510
# x-archived: 2016-10-24T02:23:53
# x-published: 2010-06-05T11:39:00
#
#
$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}
}