PoshCode Archive  Artifact [2f735c7045]

Artifact 2f735c7045f69d4682f7200037fafdfc6ae579030cbf1dad014afd40b0a29b9d:

  • File Get-Network-Utilization.ps1 — part of check-in [09964e93f7] at 2018-06-10 14:17:09 on branch trunk — get utilization from all network interfaces (user: Joel Bennett size: 1012)

# 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}
}