PoshCode Logo PowerShell Code Repository

Get Network Utilization by halr9000 28 months ago
View followups from Jason Ochoa | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1349"></script>download | new post

replace $inst with your NIC name. You can find that out by running (new-object System.Diagnostics.PerformanceCounterCategory(“network interface”)).GetInstanceNames()

  1. $cnt = 'Bytes Total/sec'
  2. $inst = 'Broadcom NetXtreme Gigabit Ethernet - Packet Scheduler Miniport'
  3. $cat = 'Network Interface'
  4. $cnt2 = 'Current Bandwidth'
  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. $util = (( $curnum * 8 ) / $maxnum ) * 100
  10. $util

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