views:

307

answers:

2

What is the PowerShell script to get the speed a specific Windows machine's network card is running at?

I know this can be done with a WMI query based statement and will post an answer once I work it out.

+2  A: 

A basic command is

Get-WmiObject -ComputerName 'servername' -Class Win32_NetworkAdapter | `
    Where-Object { $_.Speed -ne $null -and $_.MACAddress -ne $null } | `
    Format-Table -Property SystemName,Name,NetConnectionID,Speed

Note that the ComputerName parameter takes an array so you can run this against multiple computers provided you have rights. Replace the Format-Table property list with * to get a more comprehensive list of available properties. You might want to filter on these properties to get rid of entries you aren't interested in.

Using the built in byte Multiplier suffixes (MB, GB etc) would also make the speed more readable depending on your needs. You could specify this as a HashTable entry on the Format-Table -Property array e.g.

Format-Table -Property NetConnectionID,@{Label='Speed(GB)'; Expression = {$_.Speed/1GB}}
Martin Hollingsworth
A nice answer! I'd remove the `-ne $null` parts.
Jay Bazuzi
There are actually quite a few entries returned for the Win32_NetworkAdapter class, check it out. I'm using the -ne $null to filter out entries so I can see the actual entries for real physical cards but you can adapt as you see fit.
Martin Hollingsworth
[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() works against the local machine only.
Martin Hollingsworth
I think Jay is saying that the filter could be simplified to `Where {$_.Speed -and $_.MACAddress}`. As long is neither are 0 or $false, that simplified predicate will work just fine. Besides you would probably want to filter out a value of 0 anyway.
Keith Hill
Ah ha! Thanks. I clearly have a way to go with my PowerShell syntax.
Martin Hollingsworth
I'm wondering if keeping the -ne $null has some value in being explicit over the terse syntax.
Martin Hollingsworth
It obviously will allow a value of 0 then, too. That should be the only difference.
Joey
A: 

the speed property , does not exists for older servers such as: Windows Server 2003, Windows XP, Windows 2000, and Windows NT 4.0.

does anyone know how to do it in a different way ?

Liron Prihar