PowerShell script to get network card speed of a Windows Computer

≡放荡痞女 提交于 2019-12-23 08:37:11

问题


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.


回答1:


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}}



回答2:


Starting with Windows 8/Server 2012, you can try Get-NetAdapter and several more specialized commands like Get-NetAdapterAdvancedProperty:

https://docs.microsoft.com/en-us/powershell/module/netadapter/get-netadapter

You can also use the more comprehensive WMI class MSFT_NetAdapter to create customized output. MSFT_NetAdapter is described here:

https://msdn.microsoft.com/en-us/library/Hh968170(v=VS.85).aspx

Here's a command to list the speed and other properties of enabled (State 2), connected (OperationalStatusDownMediaDisconnected $false), 802.3 wired (NdisPhysicalMedium 14), non-virtual adapters on the local computer:

Get-WmiObject -Namespace Root\StandardCimv2 -Class MSFT_NetAdapter | `
  Where-Object { $_.State -eq 2 -and $_.OperationalStatusDownMediaDisconnected -eq $false -and `
                 $_.NdisPhysicalMedium -eq 14 -and $_.Virtual -eq $false } | `
  Format-Table Name,Virtual,State,NdisPhysicalMedium, `
  @{Label='Connected'; Expression={-not $_.OperationalStatusDownMediaDisconnected}}, `
  @{Label='Speed(MB)'; Expression = {$_.Speed/1000000}}, `
  FullDuplex,InterfaceDescription



回答3:


My current version, taking out bluetooth and wireless cards (run with powershell -file script.ps1):

# return network speed as exit code

$speed = Get-WmiObject -Class Win32_NetworkAdapter | 
where { $_.speed -and $_.macaddress -and 
$_.name -notmatch 'wireless|wi-fi|bluetooth|802\.11' } | select -expand speed
exit $speed/1000000


来源:https://stackoverflow.com/questions/3002473/powershell-script-to-get-network-card-speed-of-a-windows-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!