Network Adapter speed and duplex

One thing that can cause problems on the network is the duplex setting on the network adapter.  If this doesn’t match the switch port then at best you will get performance issues and at worst no connectivity.

The speed of the connection can be obtained from Win32_NetworkAdapter but for the duplex setting we need to go to the registry.

function test-duplex {            
[CmdletBinding()]            
param (            
 [string]$computer="."            
)            
BEGIN {            
 $HKLM = 2147483650            
 $reg = [wmiclass]"\\$computer\root\default:StdRegprov"            
 $keyroot = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"            
}            
            
PROCESS {            
            
Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $computer -Filter "IPEnabled='$true'" |            
foreach {            
            
$data = $_.Caption -split "]"            
$suffix = $data[0].Substring(($data[0].length-4),4)            
$key = $keyroot + "\$suffix"            
            
$value = "*PhysicalMediaType"            
$pmt = $reg.GetDwordValue($HKLM, $key, $value)  ## REG_DWORD            
            
## 0=Unspecified, 9=Wireless, 14=Ethernet            
if ($pmt.uValue -eq 14){            
            
$nic = $_.GetRelated("Win32_NetworkAdapter") | select Speed, NetConnectionId            
            
$value = "*SpeedDuplex"            
$dup = $reg.GetStringValue($HKLM, $key, $value)  ## REG_SZ            
            
switch ($dup.sValue) {            
 "0" {$duplex = "Auto Detect"}            
 "1" {$duplex = "10Mbps \ Half Duplex"}            
 "2" {$duplex = "10Mbps \ Full Duplex"}            
 "3" {$duplex = "100Mbps \ Half Duplex"}            
 "4" {$duplex = "100Mbps \ Full Duplex"}            
}             
            
New-Object -TypeName PSObject -Property @{            
  NetworkConnector = $($nic.NetConnectionID )            
  DuplexSetting = $duplex            
  Speed = $($nic.Speed)            
}            
            
} #if            
} #foreach            
} #process            
} #function

Start by defining the information we need to read the registry

Get the Win32_NetworkAdapterConfiguration for those adapters that are IP enabled. We then test the physical media type and if its ethernet we get the duplex setting. The nework connectioid is retrieved to identify the card and an object is created to pull the output together

Published Fri, Jul 29 2011 22:07 by RichardSiddaway

Comments

# re: Network Adapter speed and duplex

Hi Richard, love your posts.

Where can I find the enum values of $dup.sValue?

My workstation returns 6. And the nic settings say it's 1.0 Gbps Full Duplex.

I wonder if there's any published list of enumeration values.

Tuesday, August 02, 2011 2:58 PM by Jason

# re: Network Adapter speed and duplex

I found the values I used in an old script :-) but the full list can be found here

msdn.microsoft.com/.../ff548866(v=VS.85).aspx

I'll re-post the script to show the full range

Wednesday, August 03, 2011 3:27 AM by RichardSiddaway

# Network speeds–the faster ones

Wednesday, August 03, 2011 3:35 AM by Richard Siddaway's Blog

# Network speeds–the faster ones

Wednesday, August 03, 2011 3:58 AM by Richard Siddaway's Blog

# re: Network Adapter speed and duplex

Nice use of the GetRelated!

Thursday, April 12, 2012 10:01 AM by jrich

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: