用于获取Windows计算机的网卡速度的PowerShell脚本
问题描述:
什么是PowerShell脚本以获取特定Windows计算机网卡的运行速度?用于获取Windows计算机的网卡速度的PowerShell脚本
我知道这可以用基于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
一个很好的答案!我会删除'-ne $ null'部分。 – 2010-06-09 02:11:12
实际上Win32_NetworkAdapter类返回了很多条目,请查看它。我使用-ne $ null来过滤条目,以便我可以看到实际物理卡的实际条目,但是您可以根据需要进行修改。 – 2010-06-09 06:34:06
[System.Net.NetworkInformation.NetworkInterface] :: GetAllNetworkInterfaces()仅针对本地机器。 – 2010-06-09 08:16:48