Parallel Universe - MS Tech Blog

The ramblings of a PFE

powershell simple bandwidth monitor

powershell simple bandwidth monitor

  • Comments 3
  • Likes

very simple bandwidth monitor

allows you to select your interface and will take the average bandwidth over 60 seconds (you can configure!)

here it is !....



$interfaces = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |select name
$totalnoint = $interfaces.count

Write-Host "Please select the interface you wish to use by selecting its number and pressing enter to continue `n"
For ($cnt = 0;$cnt -lt $totalnoint;$cnt++)
 Write-Host "$cnt.`t" $interfaces[$cnt].name

$result = Read-host

$name = $interfaces[$result].name
Write-Host "Working with Interface:`t" $name

$interfacebw = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |where {$_.Name -eq $name} |select CurrentBandwidth
$intbwbytes = $interfacebw.currentbandwidth /8
$timer = 60
$waitMinutes = 1
$startTime = get-date
$endTime   = $startTime.addMinutes($waitMinutes)
$timeSpan = new-timespan $startTime $endTime
$count = 0
$avgvalue = 0

while ($timespan -gt 0)
 $timeSpan = new-timespan $(Get-Date) $endTime
 $currentbytespersec = Get-WmiObject -class Win32_PerfFormattedData_Tcpip_NetworkInterface |where {$_.Name -eq $name} |select BytesTotalPersec
 [int]$linkutil = ($currentbytespersec.bytestotalpersec / $intbwbytes) * 100
 $value = "{0:N2}" -f $linkutil
 Write-Host "Link is $value% utilized"
 $avgvalue = $avgvalue + $value
 Write-Host $timespace.seconds

$avgbw = $avgvalue / $count
$value = "{0:N2}" -f $avgbw
Write-Host "Average BW is:`t $value Bytes/Sec"

  • Is this a simple and safe script to run on the Lync server front end NIC ?

  • How to writ function for this powershell, so i can get output in one .csv file

  • Hi Ted,

    Please help me

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment