PoshCode Archive  Artifact [7b0c1a054a]

Artifact 7b0c1a054a22dd80da904a6be58d01ae56cc79f31ecf7a0b04afb18aeb29c39b:

  • File Get-Network-Utilization.ps1 — part of check-in [611698f150] at 2018-06-10 13:02:39 on branch trunk — get utilization from all network interfaces (user: Jason Ochoa size: 1038)

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