powershell simple bandwidth monitor
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
cls
Write-Host "Link is $value% utilized"
$avgvalue = $avgvalue + $value
$count++
Write-Host $timespace.seconds
}
$avgbw = $avgvalue / $count
$value = "{0:N2}" -f $avgbw
Write-Host "Average BW is:`t $value Bytes/Sec"
Comments
Anonymous
April 03, 2012
Is this a simple and safe script to run on the Lync server front end NIC ?Anonymous
December 01, 2014
How to writ function for this powershell, so i can get output in one .csv fileAnonymous
December 01, 2014
Hi Ted,
Please help me