PoshCode Archive  Artifact [b022c285f9]

Artifact b022c285f9fee0d7f9c9d90277b903d253a270c16d353384c6c09985406be89b:

  • File Get-Network-Utilization.ps1 — part of check-in [5fa94d4f77] at 2018-06-10 12:56:55 on branch trunk — get utilization from all network interfaces (user: halr9000 size: 966)

# encoding: ascii
# api: powershell
# title: Get Network Utilization
# description: get utilization from all network interfaces
# version: 0.1
# author: halr9000
# license: CC0
# x-poshcode-id: 1352
# x-derived-from-id: 1900
# x-archived: 2016-10-20T07:00:22
# x-published: 2009-09-29T17:16:00
#
#
$cnt = 'Bytes Total/sec'
$cat = 'Network Interface'
$cnt2 = 'Current Bandwidth'
foreach ($inst in ((new-object System.Diagnostics.PerformanceCounterCategory("network interface")).GetInstanceNames())){
	$cur = New-Object system.Diagnostics.PerformanceCounter($cat,$cnt,$inst)
	$max = New-Object system.Diagnostics.PerformanceCounter($cat,$cnt2,$inst)
	$curnum = $cur.NextValue()
	$maxnum = $max.NextValue()
	$ObjUtil = New-Object System.Object
	$ObjUtil | Add-Member -MemberType NoteProperty -Name "Util" -Value ((( $curnum * 8 ) / $maxnum ) * 100)
	$ObjUtil | Add-Member -MemberType NoteProperty -Name "InstanceName" -Value $inst
	$ObjUtil
}