Since I don't have Windows 8 (and Get-NetAdapterAdvancedProperty
) I used this to get the Speed/Duplex:
Update: This was driving me crazy. I was getting various errors with keys not existing, and it turns out certain devices will not have a speed/duplex like USB passthrough and Microsoft Cluster device. I updated it to use the enum value of duplex and also cycle through all available NICs.
Also, the original wasn't looking at the registry on the target, rather the 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)
}
}
}
}
It's a little clunky hardcoding that registry key, but it seems to work on my Windows 7 PC and remote servers (2003/2008/2012). From this article : "The subkey represents the class of network adapter devices that the system supports."
Output of the script:
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