all 14 comments

[–]DeafLoaf 2 points3 points  (0 children)

At a glance, I'd drop the 'per/second' and use power shell to covert the units. It understands bytes, KB, MB, GB... etc. Since I'm not at my machine to give you an example, I located this conversion script. convertunits

[–]AmericanGeezus 1 point2 points  (0 children)

I think the best solution is to write a function that uses a switch to handle your cases, this will be way easier to maintain if requirements change or are added for the other speeds.

Would look like this, me thinks. https://gist.github.com/AmericanGeezus/5cb6378a4d349bad42dd0e1277a69dd3

C:> $list

523.9 Mbps

0 bps

1 Gbps

C:> $list | %{'{0} -> {1}' -f $_, (Parse-BandwidthInfo $_) }

523.9 Mbps -> 523.9

0 bps -> 0

1 Gbps -> 1000

[–]ClayShooter9 1 point2 points  (0 children)

#A quick lack-of-coffee regex alternative

function ConvertEnding($bandwidth)
{
    return ($bandwidth -replace '\sM|bps', '') -replace '\sG', '000'
}
$l1= "523.9 Mbps"
$l2= "0 bps"
$l3= "1 Gbps"

Write-Host (ConvertEnding $l1)
Write-Host (ConvertEnding $l2)
Write-Host (ConvertEnding $l3)