Windows Server TechCenter > Windows Server Forums > Windows PowerShell > Convert bytes to MB with Get-counter
Ask a questionAsk a question
 

AnswerConvert bytes to MB with Get-counter

  • Tuesday, November 03, 2009 12:17 AMShimon1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi All
    I got this small "script" that gives the network interface trafffic status using powershell v2 CTP 3.
    I trying to convert the bytes to MB.
    Can soneone help ?
    Here is the code:
    get-counter -counter "\Network Interface(*)\Bytes Sent/sec", "\Network Interface(*)\Bytes Received/sec" -SampleInterval 6

    Simon

Answers

  • Tuesday, November 03, 2009 2:23 AMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Try this to the end of your command above:
    PS>get-counter ... -sampleinterval 6|select -exp countersamples|ft -a instancename,@{l="value";e={[math]::round($_.cookedvalue/1MB,5)}}

All Replies

  • Tuesday, November 03, 2009 2:23 AMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Try this to the end of your command above:
    PS>get-counter ... -sampleinterval 6|select -exp countersamples|ft -a instancename,@{l="value";e={[math]::round($_.cookedvalue/1MB,5)}}
  • Tuesday, November 03, 2009 4:39 AMShimon1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi there,

    I tried this but it's not doing any thing, here is the full command
    get-counter -counter "\Network Interface(*)\Bytes Sent/sec", "\Network Interface(*)\Bytes Received/sec" -sampleinterval 6 |select -exp countersamples|ft -a instancename,@{l="value";e={[math]::round($_.cookedvalue/1MB,5)}}

    cheers
    simon
  • Tuesday, November 03, 2009 12:06 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Can you show some examples?

    Here's the first few lines of output when I run it as above:

    InstanceName                                      value
    ------------                                      -----
    local area connection - virtual network               0
    broadcom netlink [tm] fast ethernet                   0
    internal                                              0
    dell wireless 1505 draft 802.11n wlan mini-card 0.00031
  • Wednesday, November 04, 2009 2:31 AMShimon1 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi There, I just get a blank screen. P.S I'm using Powershell v2 CTP3. Simon
  • Wednesday, November 04, 2009 4:47 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi There, I just get a blank screen. P.S I'm using Powershell v2 CTP3. Simon

    Try taking my last command and trimming it down to see at what point you do get some output.

    1. Remove "|ft -a ...".
    2. Test.
    3. Remove "|select -exp ...".
    4. Test.

    Let me know...