PowerShell脚本来获取Windows计算机的网卡速度

什么是PowerShell脚本来获得特定Windows机器的网卡运行的速度?

我知道这可以通过一个基于WMI查询的语句来完成,一旦我解决了,就会发布一个答案。

一个基本的命令是

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

请注意,ComputerName参数需要一个数组,以便您可以在多台计算机上运行,​​只要您有权限。 用*****替换Format-Table属性列表以获得更全面的可用属性列表。 您可能需要过滤这些属性以摆脱您不感兴趣的条目。

使用内置的字节乘数后缀(MB,GB等)也可以使速度更可读取决于您的需求。 您可以将其指定为Format-Table -Property数组上的HashTable条目,例如

 Format-Table -Property NetConnectionID,@{Label='Speed(GB)'; Expression = {$_.Speed/1GB}} 

我目前的版本,拿出蓝牙和无线网卡(使用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