用于获取 Windows 计算机网卡速度的 PowerShell 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3002473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PowerShell script to get network card speed of a Windows Computer
提问by Martin Hollingsworth
What is the PowerShell script to get the speed a specific Windows machine's network card is running at?
获得特定 Windows 机器网卡运行速度的 PowerShell 脚本是什么?
I know this can be done with a WMI query based statement and will post an answer once I work it out.
我知道这可以通过基于 WMI 查询的语句来完成,一旦我解决了,就会发布答案。
回答by Martin Hollingsworth
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.
请注意,ComputerName 参数采用一个数组,因此您可以在拥有权限的情况下对多台计算机运行它。将 Format-Table 属性列表替换为 ***** 以获得更全面的可用属性列表。您可能希望过滤这些属性以去除您不感兴趣的条目。
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.
根据您的需要,使用内置的字节乘数后缀(MB、GB 等)也会使速度更具可读性。您可以将其指定为 Format-Table -Property 数组上的 HashTable 条目,例如
Format-Table -Property NetConnectionID,@{Label='Speed(GB)'; Expression = {$_.Speed/1GB}}
回答by Mark Berry
Starting with Windows 8/Server 2012, you can try Get-NetAdapter
and several more specialized commands like Get-NetAdapterAdvancedProperty
:
从 Windows 8/Server 2012 开始,您可以尝试Get-NetAdapter
一些更专业的命令,例如Get-NetAdapterAdvancedProperty
:
https://docs.microsoft.com/en-us/powershell/module/netadapter/get-netadapter
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:
您还可以使用更全面的 WMI 类MSFT_NetAdapter
来创建自定义输出。MSFT_NetAdapter
在这里描述:
https://msdn.microsoft.com/en-us/library/Hh968170(v=VS.85).aspx
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:
这是一个命令,用于列出本地计算机上已启用(状态 2)、已连接(OperationalStatusDownMediaDisconnected $false)、802.3 有线(NdisPhysicalMedium 14)、非虚拟适配器的速度和其他属性:
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
回答by js2010
My current version, taking out bluetooth and wireless cards (run with powershell -file script.ps1):
我当前的版本,取出蓝牙和无线网卡(使用 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