![需要命令行来测试 Windows NIC 卡上的双工状态](https://linux22.com/image/1408158/%E9%9C%80%E8%A6%81%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%9D%A5%E6%B5%8B%E8%AF%95%20Windows%20NIC%20%E5%8D%A1%E4%B8%8A%E7%9A%84%E5%8F%8C%E5%B7%A5%E7%8A%B6%E6%80%81.png)
这适用于 Windows 7
我尝试了以下 powershell 命令
get-wmiobject Win32_NetworkAdapter | foreach-object { get-wmiobject -namespace root/WMI -class MSNdis_macOptions -filter "InstanceName='$($_.Name)'"}
但我似乎无法从中获取有用的信息。
答案1
由于我没有 Windows 8(和Get-NetAdapterAdvancedProperty
),所以我用它来获取速度/双工:
更新:这让我抓狂了。我遇到了各种错误,密钥不存在,而且事实证明某些设备没有速度/双工,如 USB 直通和 Microsoft 群集设备。我将其更新为使用双工的枚举值,并循环遍历所有可用的 NIC。
此外,原来没有查看目标上的注册表,而是查看本地主机。
Function Get-NICSpeedDuplex {
Param (
[String]$computer
)
$key = "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
gwmi -Class Win32_NetworkAdapterConfiguration -Computer $computer -Filter "IPEnabled='$true'" | % {
$suffix = $([String]$_.Index).PadLeft(4,"0")
#get remote registry value of speed/duplex
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$service = $reg.OpenSubKey("$key\\$suffix\\Ndi").GetValue("Service")
If ($service -imatch "usb") {
# This USB device will not have a '*SpeedDuplex' key
New-Object PSObject -Property @{
"Device" = $_.Description
"Speed/Duplex" = "USB Device"
}
} ElseIf ($service -imatch "netft") {
# Microsoft Clustered Network will not have a '*SpeedDuplex' key
New-Object PSObject -Property @{
"Device" = $_.Description
"Speed/Duplex" = "Cluster Device"
}
} Else {
$speedduplex = $reg.OpenSubKey("$key\\$suffix").GetValue("*SpeedDuplex")
$enums = "$key\$suffix\Ndi\Params\*SpeedDuplex\enum"
New-Object PSObject -Property @{
"Device" = $_.Description
"Speed/Duplex" = $reg.OpenSubKey($enums).GetValue($speedduplex)
}
}
}
}
对该注册表项进行硬编码有点笨拙,但它似乎可以在我的 Windows 7 PC 和远程服务器(2003/2008/2012)上运行。来自本文:“该子项代表系统支持的网络适配器设备类。”
脚本输出:
PS C:\> Get-NICSpeedDuplex "test-server-xx" | ft -auto
Speed/Duplex Device
------------ ------
Auto Negotiation vmxnet3 Ethernet Adapter
Auto Negotiation vmxnet3 Ethernet Adapter #4
Cluster Device Microsoft Failover Cluster Virtual Adapter