由于我没有Windows 8(和Get-NetAdapterAdvancedProperty
),我使用它来获得速度/双工:
更新:这让我发疯了。我的密钥不存在会出现各种错误,事实证明某些设备没有像USB直通和Microsoft群集设备那样的速度/双工。我更新它以使用双工的枚举值,并循环浏览所有可用的NIC。
此外,原始版本没有查看目标上的注册表,而是查看localhost。
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