Gathering all sorts of server information with Powershell is rather easy, using the Get-WmiObject cmdlet.

In order to get NIC settings, the following little script returns a LOT of information:

$serverName = Read-Host “Enter server name”
$NicConfig = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName $serverName
$NicConfig | Format-List *

The one thing I was missing though, is the value of the NIC Speed and Duplex. So I started to dig into the registry and found a way to discover these values.
The following key holds the information I’m looking for:

HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}

The subkeys are named after the ID’s of the different NICs, so I can match them against the SettingId property of the Wmi output. Now the trick is in identifying what vendor/model the NIC (or at least the chip) is. That’s because every rband will have the Speed / Duplex setting stored in a different key. Also, the values of that key are illegible, and the translation to readable output is stored in even different subkeys. That’s to keep things simple :|

Lucky for you, I have already figured out a way to decypher all this and the following script has the information for the three most frequently used brands embedded. So, download, rename to .ps1 and have fun!

Get-NICSettings (rename to .ps1)

Tagged with:
 

45 Responses to Gather NIC properties (including Speed and Duplex)

  1. Pete Solano says:

    I really need to get this to work, and it’s not working. Please help!

  2. admin says:

    Pete,
    Please post your output so I can help you.
    Hugo

  3. Matthew says:

    A nice script indeed, but do you know how this would work with a text file containing server names? When I use a ForEach statement and have it take servername from the text file, it only shows results for the last entry in the text file instead of every entry in the ForEach statement. Do you have any suggestions on how I can troubleshoot the problem?

  4. admin says:

    Hi Matthew,

    Try replacing the first line of the script with:
    $servernames = Get-Content FILENAME
    ForEach ($servername in $servernames){
    Write-Host “*************”
    Write-Host $servername
    Write-Host “*************”

    ORIGINAL SCRIPT HERE

    }

    ——-
    PS: You might want to add a Clear-Variable VARIABLENAME line for each of the used variables before looping to the next server. If reading the registry fails, you might get values from the previous server, see?

  5. Marc Wojck says:

    I ran into a bit of a quandry. In my environment for the HP NIC type there seems to be two different drivers for the same NC373i NIC. Unfortunately the speed and duplex is stored like you have it for one type in req_medium and in the other type it is stored in *SpeedDuplex. Obviously to add the additional NIC I have to make some changes because the ComponentID for both are the same. This creates a bit of a problem. I assume I will need to create some type of a condition to make this work. Any ideas?

    This script is awesome and it has a lot of potential. I am currently collecting speed and duplex settings for all hosts in my DC 2000 plus hosts. A complete nightmare to do manually!!! Any help with this would be excellent!!!

    Thanks,
    Marc

  6. Marc Wojck says:

    Thanks for all of you hard work!!!

  7. Marc says:

    I am trying to get this script to work in the same fashion but I have not been able to lock it down. Any suggestions on how to get this script working using a list of hosts and leave the hostname, ipaddress and speed/duplex? This would be a huge help!!!

  8. admin says:

    @Marc Wojck
    Try using an IF / ELSE construction based on wether the subkey exists. Something like this:
    If ($subKey.GetValue(“SpeedDuplex”) -ne $null)
    {#retrieve values from SpeedDuplex key}
    ElseIf ($subKey.GetValue(“req_medium”) -ne $null)
    {#retrieve values from req_medium key}

  9. Marc says:

    Thank you very much!! This is what it looks like when it is working.

    ElseIf ($componentID -match “b06bdrv”)
    {
    $myObj.NICModel = “HP”
    $HP = $subKey.GetValue(“req_medium”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\req_medium\Enum”)
    $myObj.NICModel = “HP2″
    $HP2 = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“ndi\params\*SpeedDuplex\enum”)
    If ($subKey.GetValue(”req_medium”) -ne $null)
    {$myObj.SpeedDuplex = $enum.GetValue(“$HP”) >> c:\temp\speedduplexreport.txt}
    ElseIf ($subKey.GetValue(”*SpeedDuplex”) -ne $null)
    {$myObj.SpeedDuplex = $enum.GetValue(“$HP2″) >> c:\temp\speedduplexreport.txt}

  10. This is great work Hugo! Thanks for sharing!

  11. Kiran says:

    Hi this script pretty much works but would you know how to pass credentials using the remote registry method.Thats the only part of the missing puzzle right now.

    by the way thanks for the great script.

    • admin says:

      Kiran,

      The remote registry method does not support alternate credentials. You could however:
      - use runas to launch the script, or
      - launch a new powershell instance from within the script every time you need alternate credentials
      Just some thoughts.
      Hugo

  12. Kiran says:

    hmm thats disappointing but thanks anyway.

  13. Marty says:

    In addition to getting the NIC settings, could get if the NIC is in promiscuous mode with this code:
    http://praetorianprefect.com/archives/2009/09/whos-being-promiscuous-in-your-active-directory/

  14. Jonny Barker says:

    This script is awesome. I’ve been trying to write something like this for weeks, I’m kind of new to powershell I was getting close but you have saved me a ton of work, thank you very much. The only tweak I’d like to include is for the output to go to a file rather than screen so that I can search it for “SpeedDuplex : Auto”
    I think that the code for that would be something like this but I’m not 100%:

    $logFilePath = new-item -type file -name “$(get-date -uformat ‘%Y%m%d%H%M%S’)-filename.csv”

    $servernames = Get-Content C:\PowerShell\Scripts\GetRemoteRegistry\feedlist.txt
    ForEach ($servername in $servernames){
    Write-Ouput $servername out-file $logfilepath -append

    Any help is most appreciated
    Thanks and regards

    Jonny Barker

  15. Jeff Tripe says:

    I’m trying to retrieve speed/duplex settings for the virtual nics in our VM’s i.e autonegotiate or 100mbps. This script will find the VMWare Accelerated AMD PCI Net Adapter, IP, etc, but will return “unknown” for speed and duplex. I’m not a developer/coder so I apologize in advance for what may be an obvious modification that will return what I need. Thanks!

    • admin says:

      Every make/model of NIC has it’s own set of registry keys to store the speed/duplex settings. Go explore to find them. They usually use some code to set the value and have an enumeration of codes and the respective readable equivalents. All you need to do is find the key names for the values and the enums and add them to the script.

  16. Krish says:

    I’ve noticed that some VMware Adapters use “FDUP” to store duplex setting.

  17. Douglas Santos says:

    Hi Pete,

    Firstly thanks for the script I´m trying to run the script to get speed nic info, but all server has HP network team, when I run the scritpt its give me as unknow.

    can you help me to solve this problem?

    Regards,

    Doug

  18. mat grove says:

    thanks for this – for the HP teaming I just extrated the TeamType reg key from the subkey.
    and compared it to the list : (this will give you how the team is setup)

    Automatic (Recommended)
    802.3ad Dynamic with Fault Tolerance
    802.3ad Dynamic Dual Channel Load Balancing (INP)
    Switch-assisted Load Balancing with Fault Tolerance (SLB)
    Switch-assisted Dual Channel Load Balancing (INP)
    Transmit Load Balancing with Fault Tolerance (TLB)
    Transmit Load Balancing with Fault Tolerance and Preference Order
    Channel-based Transmit Load Balancing
    Transmit Load Balancing with NFT and Dual Receive
    Channel-based Transmit Load Balancing with Dual Receive
    Network Fault Tolerance Only (NFT)
    Network Fault Tolerance with Preference Order
    Switch-assisted Dual Channel Network Fault Tolerance (INP)
    Switch-assisted Dual Channel NFT and Preference Order (INP)
    802.3ad Dynamic Dual Channel Network Fault Tolerance (INP)
    802.3ad Dynamic Dual Channel NFT and Preference Order (INP)

  19. Brian says:

    When I try to run the program it just comes back with the name of the of the server with a flashing cursor beside it. I made sure the policy is set to Unrestricted. Is there any other setting I’m missing?

  20. [...] if you want a Powershell script, there ia a nice example here. « How to configure TCP/IP from the Command Prompt LikeBe the first to like [...]

  21. Hi I’m getting the following error on running it.

    Exception calling “OpenSubKey” with “1″ argument(s): “Requested registry access is not allowed.”
    At line:22 char:33
    + $subKey = $baseKey.OpenSubKey <<<< ("$subKeyName")
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    (one time for each NIC)

  22. [...] Gather NIC properties including Speed and Duplex. GA_googleAddAttr("AdOpt", "1"); GA_googleAddAttr("Origin", "other"); GA_googleAddAttr("LangId", [...]

  23. Richard Norman says:

    This works well but there are a few things to make note of.

    When going through the keys it does not take into account the “property” key that is there. It only go through the numbered keys.

    Second some of the paths are different on my Windows 7 machine here. Here are the repaired paths for broadcom network card I have:


    $SD = $subKey.GetValue("*SpeedDuplex")
    $enum = $subKey.OpenSubKey("NdiParams*SpeedDuplexEnum")
    $myObj.SpeedDuplex = $enum.GetValue("$SD")

    I will update and post to my blog as well. But in all excellent script and find.

  24. Joe says:

    Would be ideal if someone would take the script, allow a text file of servers, support the major makers of servers and NICs, e.g., IBM, Dell, HP, Intel, Broadcom and ESX/VMware with speed and duplex support and publish.

  25. Juliennas says:

    Hi all,
    In order to help Joe, I’ve updated Hugo’s script, with Broadcom teaming registry values and some VMware cards. There is still Intel teaming that is missing… If anyone had servers with Intel teamtype values, it would be great to had it.
    Also, I’ve added an excel output, because I needed it to make reportings.
    It may be not written with the best practices, so if you’d like to rewrite it, feel free and share.

    Here is the code :

    CLEAR
    Write-Host “*************************************” -ForegroundColor Blue
    Write-Host ” Windows Server NIC Inventory ” -ForegroundColor Blue
    Write-Host “*************************************” -ForegroundColor Blue
    Write-Host ” ! Needs Domain Admin Rights ! ” -ForegroundColor Red -BackgroundColor Black

    #Init
    $erroractionpreference = “SilentlyContinue”
    $Connected = 2
    $date = Get-Date -format yyyy-MM-dd
    $InputFile = “where you’ve located the input server file.txt”
    $ExportPathNIC = “where to save”
    $ReportNIC = $date + “-ReportingNIC.xls”
    $ExcelBookNIC = $ExportPathNIC + $ReportNIC

    #Excel report
    $ExcelNIC = New-Object -Com Excel.Application
    $ExcelNIC.visible = $true
    $WorkbookNIC = $ExcelNIC.Workbooks.Add()
    $SheetNIC = $ExcelNIC.Worksheets.Item(1)
    $SheetNIC.Name = “NIC”
    $SheetNIC.Cells.Item(1,1) = ” Server Name ”
    $SheetNIC.Cells.Item(1,2) = ” Manufacturer”
    $SheetNIC.Cells.Item(1,3) = ” Card Name ”
    $SheetNIC.Cells.Item(1,4) = ” Speed & Duplex ”
    $SheetNIC.Cells.Item(1,5) = ” IP Address(es) ”
    $SheetNIC.Cells.Item(1,6) = ” SubNet ”
    $SheetNIC.Cells.Item(1,7) = ” Gateway ”
    $SheetNIC.Cells.Item(1,8) = ” DNS Servers”
    $SheetNIC.Cells.Item(1,9) = ” Teaming Manufacturer”
    $SheetNIC.Cells.Item(1,10) = ” Teaming Type ”

    $colSheets = ($SheetNIC)
    Foreach ($colorItem in $colSheets)
    { $intRowNIC = 2
    $WorkbookNIC = $colorItem.UsedRange
    $WorkbookNIC.Font.Size = 7
    $WorkbookNIC.Interior.ColorIndex = 20
    $WorkbookNIC.Font.ColorIndex = 11
    $WorkbookNIC.Font.Bold = $True }

    #Start:
    $ServerNames = Get-Content $InputFile

    Foreach ($ServerName in $ServerNames) {
    Write-Host “Inspecting $ServerName”
    $SheetNIC.Cells.Item($intRowNIC,1) = $ServerName
    $NicConfig = Gwmi -Class Win32_NetworkAdapterConfiguration -Comp $ServerName
    $myCol = @()
    ForEach ($Nic in $NicConfig) {
    $myObj = “” | Select-Object Description, IPAddress, IPSubnet, DefaultIPGateway, DNSServers, NICModel, SpeedDuplex
    $myObj.Description = $Nic.Description
    $myObj.IPAddress = [STRING]$Nic.IPAddress
    $myObj.IPSubnet = $Nic.IPSubnet
    $myObj.DefaultIPGateway = $Nic.DefaultIPGateway
    $myObj.DNSServers = [STRING]$Nic.DNSServerSearchOrder

    $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $serverName)
    $baseKey = $registry.OpenSubKey(“SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}”)
    $subKeyNames = $baseKey.GetSubKeyNames()
    ForEach ($subKeyName in $subKeyNames) {
    $subKey = $baseKey.OpenSubKey(“$subKeyName”)
    $ID = $subKey.GetValue(“NetCfgInstanceId”)
    If ($ID -eq $Nic.SettingId) {
    $componentID = $subKey.GetValue(“ComponentID”)

    #Broadcom Cards
    If ($componentID -match “ven_14e4″) {
    $myObj.NICModel = “Broadcom”
    $requestedMediaType = $subKey.GetValue(“RequestedMediaType”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\RequestedMediaType\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$requestedMediaType”) }

    #HP cards with Chipset Broadcom
    ElseIf ($componentID -match “b06bdrv”) {
    $myObj.NICModel = “HP”
    $SD = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“BRCMNdi\Params\*SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Broadcom Teaming
    ElseIf ($componentID -match “brcm_blfm”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming Broadcom”
    Switch ($Team = $subKey.GetValue(“TeamType”)){
    0{$SheetNIC.Cells.Item($intRowNIC,10) = “Smart Load Balancing & FailOver”}
    1{$SheetNIC.Cells.Item($intRowNIC,10) = “Smart Load Balancing”}
    2{$SheetNIC.Cells.Item($intRowNIC,10) = “Link Aggregation (802.3ad) “}
    3{$SheetNIC.Cells.Item($intRowNIC,10) = “Generic Trunking (FEC/GEC)/802.3ad-Draft Static”}
    4{$SheetNIC.Cells.Item($intRowNIC,10) = “SLB (Auto-Fallback Disable)”}
    Default{$SheetNIC.Cells.Item($intRowNIC,10) = “Undetermined”} } }

    #Intel Cards
    ElseIf ($componentID -match “ven_8086″) {
    $myObj.NICModel = “Intel”
    $SD = $subKey.GetValue(“SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Teaming Intel ==> Need to Improve !!
    ElseIf ($componentID -match “iansminiport”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming Intel”
    }

    #VMware
    ElseIf ($componentID -match “ven_15ad” -or $componentID -match “ven_1022″ ) {
    $myObj.NICModel = “VMware
    $SD = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\*SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Unknown Cards
    Else {
    $myObj.NICModel = “Unknown”
    $myObj.SpeedDuplex = “Unknown” }

    #Populate NIC sheet
    If ($myObj.NICModel -ne “Unknown”){
    $SheetNIC.Cells.Item($intRowNIC,2) = $myObj.NICModel
    $SheetNIC.Cells.Item($intRowNIC,3) = $myObj.Description
    $SheetNIC.Cells.Item($intRowNIC,4) = [STRING]$myObj.SpeedDuplex
    $SheetNIC.Cells.Item($intRowNIC,5) = [STRING]$myObj.IPAddress
    $SheetNIC.Cells.Item($intRowNIC,6) = $myObj.IPSubnet
    $SheetNIC.Cells.Item($intRowNIC,7) = $myObj.DefaultIPGateway
    $SheetNIC.Cells.Item($intRowNIC,8) = [STRING]$myObj.DNSServers
    $intRowNIC = $intRowNIC + 1}
    } } } }

    #Excel Save
    $SheetNIC.SaveAs($ExcelBookNic)
    $ExcelBookNic.Quit()
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ExcelBookNic)
    Stop-Process -processname excel
    here

  26. Hector says:

    Thanks for a great looking script, however it errors for me with this
    #Broadcom Teaming
    ElseIf ($componentID -match “brcm_blfm”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming’ in expression or statement.
    + CategoryInfo : ParserError: (Broadcom”
    $req…C,9) = “Teaming:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

  27. Mark says:

    I had the same issue – it was a copy paste issue. retyped a few lines and it was fine.

  28. Hector says:

    sorry i’ve check but it errors on line 83
    #Broadcom Teaming
    ElseIf ($componentID -match “brcm_blfm”){
    SheetNIC.Cells.Item($intRowNIC,9) = “Teaming’ in expression or statement.
    + CategoryInfo : ParserError: (Broadcom”
    $req…C,9) = “Teaming:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

    Could you please post the version you have that works? i need to get Teaming details for dell poweredge servers – thanks

  29. Hector says:

    Here is a bit of a script that will show some network settings in html format. What i’m hoping to do is to get the teaming information of servers. If you know how to do this to this script please post.

  30. admin says:

    Hector, I can only test against HP servers with HP Teaming. WMI does nog give any more info than IP and subnet. No info on which adapters are teamed, team settings etc. Maybe you can find registry keys that host the settings you want and use remote registry to collect them?
    Hugo

  31. Hector says:

    Ok thanks….yes i’ll have to try that. Getting a full audit of server NIC’s will be good. Physical or VM…..for HP, Dell, IBM etc.

  32. RicNsa says:

    It is working however its pulling information for some of the broadcoms(NetXtreme Gigabit Ethernet) and failed to pull the info for some (same vendor). similarly, its happening for other venodr NIC as well. How do I update the script to include that information as well.

  33. RicNsa says:

    How to configure the script to check more then one location in registry for same vendor?
    I found duplex info for Broadcom at two different location

  34. RicNsa says:

    Ijust checked the server that are not reporting the data, in device manager, NIC does not have speed&duplex,so its missing in registry…where else to look at for this data?

  35. Hector says:

    Could someone please re post the script that they have working as i can’t ressolve the error i posted – thanks

  36. RicNsa says:

    CLEAR
    Write-Host “*************************************” -ForegroundColor Blue
    Write-Host ” Windows Server NIC Inventory ” -ForegroundColor Blue
    Write-Host “*************************************” -ForegroundColor Blue
    Write-Host ” ! Needs Domain Admin Rights ! ” -ForegroundColor Red -BackgroundColor Black

    #Init
    $erroractionpreference = “SilentlyContinue”
    $Connected = 2
    $date = Get-Date -format yyyy-MM-dd
    $InputFile = “C:\MachineList.txt”
    $ExportPathNIC = “C:\”
    $ReportNIC = $date + “-ReportingNIC.xls”
    $ExcelBookNIC = $ExportPathNIC + $ReportNIC

    #Excel report
    $ExcelNIC = New-Object -Com Excel.Application
    $ExcelNIC.visible = $true
    $WorkbookNIC = $ExcelNIC.Workbooks.Add()
    $SheetNIC = $ExcelNIC.Worksheets.Item(1)
    $SheetNIC.Name = “NIC”
    $SheetNIC.Cells.Item(1,1) = ” Server Name ”
    $SheetNIC.Cells.Item(1,2) = ” Manufacturer”
    $SheetNIC.Cells.Item(1,3) = ” Card Name ”
    $SheetNIC.Cells.Item(1,4) = ” Speed & Duplex ”
    $SheetNIC.Cells.Item(1,5) = ” IP Address(es) ”
    $SheetNIC.Cells.Item(1,6) = ” SubNet ”
    $SheetNIC.Cells.Item(1,7) = ” Gateway ”
    $SheetNIC.Cells.Item(1,8) = ” DNS Servers”
    $SheetNIC.Cells.Item(1,9) = ” Teaming Manufacturer”
    $SheetNIC.Cells.Item(1,10) = ” Teaming Type ”

    $colSheets = ($SheetNIC)
    Foreach ($colorItem in $colSheets)
    { $intRowNIC = 2
    $WorkbookNIC = $colorItem.UsedRange
    $WorkbookNIC.Font.Size = 7
    $WorkbookNIC.Interior.ColorIndex = 20
    $WorkbookNIC.Font.ColorIndex = 11
    $WorkbookNIC.Font.Bold = $True }

    #Start:
    $ServerNames = Get-Content $InputFile

    Foreach ($ServerName in $ServerNames) {
    Write-Host “Inspecting $ServerName”
    $SheetNIC.Cells.Item($intRowNIC,1) = $ServerName
    $NicConfig = Gwmi -Class Win32_NetworkAdapterConfiguration -Comp $ServerName
    $myCol = @()
    ForEach ($Nic in $NicConfig) {
    $myObj = “” | Select-Object Description, IPAddress, IPSubnet, DefaultIPGateway, DNSServers, NICModel, SpeedDuplex
    $myObj.Description = $Nic.Description
    $myObj.IPAddress = [STRING]$Nic.IPAddress
    $myObj.IPSubnet = $Nic.IPSubnet
    $myObj.DefaultIPGateway = $Nic.DefaultIPGateway
    $myObj.DNSServers = [STRING]$Nic.DNSServerSearchOrder

    $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $serverName)
    $baseKey = $registry.OpenSubKey(“SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}”)
    $subKeyNames = $baseKey.GetSubKeyNames()
    ForEach ($subKeyName in $subKeyNames) {
    $subKey = $baseKey.OpenSubKey(“$subKeyName”)
    $ID = $subKey.GetValue(“NetCfgInstanceId”)
    If ($ID -eq $Nic.SettingId) {
    $componentID = $subKey.GetValue(“ComponentID”)

    #Broadcom Cards
    If ($componentID -match “ven_14e4″) {
    $myObj.NICModel = “Broadcom”
    $requestedMediaType = $subKey.GetValue(“RequestedMediaType”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\RequestedMediaType\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$requestedMediaType”) }

    #HP cards with Chipset Broadcom
    ElseIf ($componentID -match “b06bdrv”) {
    $myObj.NICModel = “HP”
    $SD = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“BRCMNdi\Params\*SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Broadcom Teaming
    ElseIf ($componentID -match “brcm_blfm”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming Broadcom”
    Switch ($Team = $subKey.GetValue(“TeamType”)){
    0{$SheetNIC.Cells.Item($intRowNIC,10) = “Smart Load Balancing & FailOver”}
    1{$SheetNIC.Cells.Item($intRowNIC,10) = “Smart Load Balancing”}
    2{$SheetNIC.Cells.Item($intRowNIC,10) = “Link Aggregation (802.3ad) “}
    3{$SheetNIC.Cells.Item($intRowNIC,10) = “Generic Trunking (FEC/GEC)/802.3ad-Draft Static”}
    4{$SheetNIC.Cells.Item($intRowNIC,10) = “SLB (Auto-Fallback Disable)”}
    Default{$SheetNIC.Cells.Item($intRowNIC,10) = “Undetermined”} } }

    #Intel Cards
    ElseIf ($componentID -match “ven_8086″) {
    $myObj.NICModel = “Intel”
    $SD = $subKey.GetValue(“SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Teaming Intel ==> Need to Improve !!
    ElseIf ($componentID -match “iansminiport”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming Intel”
    }

    #VMware
    ElseIf ($componentID -match “ven_15ad” -or $componentID -match “ven_1022″ ) {
    $myObj.NICModel = “VMware”
    $SD = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\*SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }

    #Unknown Cards
    Else {
    $myObj.NICModel = “Unknown”
    $myObj.SpeedDuplex = “Unknown” }

    #Populate NIC sheet
    If ($myobj.NICModel -ne “Unknown”) {
    $SheetNIC.Cells.Item($intRowNIC,2) = $myObj.NICModel
    $SheetNIC.Cells.Item($intRowNIC,3) = $myObj.Description
    $SheetNIC.Cells.Item($intRowNIC,4) = [STRING]$myObj.SpeedDuplex
    $SheetNIC.Cells.Item($intRowNIC,5) = [STRING]$myObj.IPAddress
    $SheetNIC.Cells.Item($intRowNIC,6) = $myObj.IPSubnet
    $SheetNIC.Cells.Item($intRowNIC,7) = $myObj.DefaultIPGateway
    $SheetNIC.Cells.Item($intRowNIC,8) = [STRING]$myObj.DNSServers
    $intRowNIC = $intRowNIC + 1}
    } } } }

    #Excel Save
    $SheetNIC.SaveAs($ExcelBookNic)
    $ExcelBookNic.Quit()
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($ExcelBookNic)
    Stop-Process -processname excel
    here

  37. hector says:

    Many Thanks for that :)

  38. jeff says:

    Okay, but I need to have a way to set ONLY “the subnet mask.”
    How do i do that?
    In my case, ALL ip addresses are fine, but our subnet mask on all workstations needs to be modified.
    (and dns & wins, but that’s already covered above).

    Looks like setting the IP static address is the only way to also set the Network Mask???
    Like this:
    $NICs = Get-WMIObject Win32_NetworkAdapterConfiguration `
    | where{$_.IPEnabled -eq “TRUE”}
    Foreach($NIC in $NICs) {
    $NIC.EnableStatic(“192.168.171.42″, “255.255.255.0″) <– SUBNET MASK
    $NIC.SetGateways(“192.168.171.1″)
    $DNSServers = “198.102.234.125″,”198.102.234.126″
    $NIC.SetDNSServerSearchOrder($DNSServers)
    $NIC.SetDynamicDNSRegistration(“TRUE”)
    $NIC.SetWINSServer(“198.102.234.125″, “198.102.234.126″)
    }

    Or, would I do just $NIC.IPSubnet('my-new-mask")?
    OR…
    $NIC.SetIPSubnet? (that is not listed in the methods/classes, so how do we do this, without also having to set the ip address?)

  39. Yvonus says:

    Hello people.
    Quite interested in that script, while totally unknowledgable about powershell.
    For the record, I’m working with a quite big backup infrastructure.
    When backups are getting real slow on windows host, the analysis starts with a netstat -es looking for collisions and errors.
    Your script would come handy to diagnose a duplex negotiation issue.

    Unfortunately, my first test showed this on a windows 2003 host :

    You cannot call a method on a null-valued expression.
    At C:\Documents and Settings\a207296_adm\Desktop\nic.ps1:45 char:41
    + $myObj.SpeedDuplex = $enum.GetValue( <<<< "$SD")

    Description : HP NC382i DP Multifunction Gigabit Server Adapter
    DHCPEnabled : False
    IPAddress : {0.0.0.0}
    IPSubnet : {0.0.0.0}
    DefaultIPGateway :
    DNSServers :
    WINSServers : {, }
    NICModel : HP
    SpeedDuplex :

    Also :
    Description : HP NC382i DP Multifunction Gigabit Server Adapter #3
    DHCPEnabled : False
    IPAddress : {192.64.57.53, 192.64.57.50}
    IPSubnet : {255.255.255.0, 255.255.255.0}
    DefaultIPGateway : {192.64.57.254}
    DNSServers : {192.64.229.111, 192.80.229.111}
    WINSServers : {, }
    NICModel : HP
    SpeedDuplex :

    Bottom line is : it's working a bit, but not perfectly ;-)

  40. KrazY says:

    RicNsa when i user you script for a 2003 server i am getting the below error.

    Some one Help me I need a script to find for finding

    IPAddress, IPSubnet, DefaultIPGateway, DNSServers, WinServer ,NICModel, SpeedDuplex.

    duplex speed i need to know like 100MB Full or Half and what is there in device manager settings.

    Unexpected token ‘Broadcom”
    $requestedMediaType = $subKey.GetValue(“RequestedMediaType”)
    $enum = $subKey.OpenSubKey(“Ndi\Params\RequestedMediaType\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$requestedMediaType”) }
    #HP cards with Chipset Broadcom
    ElseIf ($componentID -match “b06bdrv”) {
    $myObj.NICModel = “HP”
    $SD = $subKey.GetValue(“*SpeedDuplex”)
    $enum = $subKey.OpenSubKey(“BRCMNdi\Params\*SpeedDuplex\Enum”)
    $myObj.SpeedDuplex = $enum.GetValue(“$SD”) }
    #Broadcom Teaming
    ElseIf ($componentID -match “brcm_blfm”){
    $SheetNIC.Cells.Item($intRowNIC,9) = “Teaming’ in expression or statement.
    + CategoryInfo : ParserError: (Broadcom”
    $req…C,9) = “Teaming:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Leave a Reply