PoshCode Logo PowerShell Code Repository

Get Network Utilization (modification of post by halr9000 view diff)
View followups from Joel Bennett | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1352"></script>download | new post

get utilization from all network interfaces

  1. $cnt = 'Bytes Total/sec'
  2. $cat = 'Network Interface'
  3. $cnt2 = 'Current Bandwidth'
  4. foreach ($inst in ((new-object System.Diagnostics.PerformanceCounterCategory("network interface")).GetInstanceNames())){
  5.         $cur = New-Object system.Diagnostics.PerformanceCounter($cat,$cnt,$inst)
  6.         $max = New-Object system.Diagnostics.PerformanceCounter($cat,$cnt2,$inst)
  7.         $curnum = $cur.NextValue()
  8.         $maxnum = $max.NextValue()
  9.         $ObjUtil = New-Object System.Object
  10.         $ObjUtil | Add-Member -MemberType NoteProperty -Name "Util" -Value ((( $curnum * 8 ) / $maxnum ) * 100)
  11.         $ObjUtil | Add-Member -MemberType NoteProperty -Name "InstanceName" -Value $inst
  12.         $ObjUtil
  13. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me