monitoring bandwidth via Powershell script

Hello,

I am trying to monitor the bandwidth via powershell script for that so far I have written this script to fetch the bandwidth but I have some confusions,

$query = "Select BytesTotalPersec from Win32_PerfFormattedData_Tcpip_NetworkInterface where name='Microsoft Hyper-V Network Adapter'"
Get-WmiObject -Query $query;

Output :

__GENUS          : 2
__CLASS          : Win32_PerfFormattedData_Tcpip_NetworkInterface
__SUPERCLASS     :
__DYNASTY        :
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
BytesTotalPersec : 122118
PSComputerName   :

Now I have three questions :

1) What will be the formula to convert the BytesTotalPerSec to  MB/s ?

2) Is the BytesTotalPerSec really the bandwidth utilized by the adaptor?

3) If I want to store BytesTotalPerSec value in the variable what would be the procedure.?

Thanks

Frank

September 5th, 2015 10:20am

All conversions are simple arithmetic.  Just divide buy that which you want to get.

byte / (1 megabyte) = megaytes

See: http://www.powershellmagazine.com/2013/05/20/converting-to-size-units-kb-mbgbtb-and-pb-without-using-powershell-multipliers/

Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 11:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics