# encoding: ascii
# api: powershell
# title: Get Network Utilization
# description: get utilization from all network interfaces
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 6510
# x-archived: 2016-10-29T07:25:21
# x-published: 2016-09-12T09:49: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}
}
