Get Network Adapter Properties and Advanced Properties in Windows Server 2012 and Windows 8

Introduction

This script could be used to get network adapter properties and advanced properties in Windows Server 2012 and Windows 8. This script combines the outputs of Get-NetAdapter and Get-NetAdapterAdvancedProperty. You can use this script to generate a report of network adapter configuration settings.

Download Windows Server 2012
Download Your FREE Copy of Hyper-V Server 2012

Scenarios

In a real world environment, IT Administrators are required to check the configuration of network adapters after the deployment of new servers. One typical example is the duplex setting of network adapters. Also, IT administrators need to maintain server lists which contain configuration settings for network adapters on a regular basis. Before Windows Server 2012, IT administrators often had difficulties handling these tasks.

Demo

Get Microsoft Silverlight

Script

This script contains one advanced function, Get-OSCNetAdapterProperty. You can use this script in the following ways:

Method 1:

  1. Download the script and copy it to a Windows Server 2012 or Windows 8 computer.
  2. Open the script file with Notepad or other script editors.
  3. Scroll down to the end of the script file, and then add the example command that you want to run.
  4. Save the file, and then run the script in Windows PowerShell.

Method 2:

  1. Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file).
  2. Run Import-Module cmdlet to import this module file in Windows PowerShell.Import-Module filepath\scriptname.psm1

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
#Get properties and generate the result 
foreach ($netAdapter in $netAdapters) { 
    $netAdapterName = $netAdapter.Name 
    $result = New-Object System.Management.Automation.PSObject 
    #Get all properties unless specific properties are specified 
    if (-not [system.string]::IsNullOrEmpty($Property)) { 
        foreach ($userSpecifiedProperty in $Property) { 
            $propertyValue = $netAdapterAdvPropertyKVP[$netAdapterName].$userSpecifiedProperty 
            if ($netAdapterPropertyNames.ContainsKey($userSpecifiedProperty)) { 
                $result | Add-Member -NotePropertyName $userSpecifiedProperty -NotePropertyValue $($netAdapter.$userSpecifiedProperty-Force 
            } elseif ($netAdapterAdvPropertyNames.ContainsKey($userSpecifiedProperty)) { 
                $result | Add-Member -NotePropertyName "$userSpecifiedProperty" -NotePropertyValue $propertyValue -Force 
            } 
        } 
    } else { 
        foreach ($netAdapterProperty in $netAdapterPropertyNames.Keys.GetEnumerator()) { 
            $result | Add-Member -NotePropertyName $netAdapterProperty -NotePropertyValue $($netAdapter.$netAdapterProperty-Force 
        } 
        foreach ($netAdapterAdvPropertyName in $netAdapterAdvPropertyNames.Keys.GetEnumerator()) { 
            $propertyValue = $netAdapterAdvPropertyKVP[$netAdapterName].$netAdapterAdvPropertyName 
            $result | Add-Member -NotePropertyName $netAdapterAdvPropertyName -NotePropertyValue $propertyValue -Force 
        } 
    } 
    $results +$result 
} 

Examples

Example 1: Displays help information about Get-OSCNetAdapterProperty
Command: Get-Help Get-OSCNetAdapterProperty -Full
Screenshot:

Example 2: Gets all of the visible network adapters properties and the advanced properties that have a DisplayName.
Command: Get-OSCNetAdapterProperty
Screenshot:

Example 3: Gets the name of all network adapters.
Command: Get-OSCNetAdapterProperty -IncludeHidden -Property "Name"
Screenshot:

Example 4: Gets physical network adapters properties and advanced properties that start with Driver*.
Command: Get-OSCNetAdapterProperty -Physical | Format-List Driver*
Screenshot:

Example 5: Gets all of the properties and advanced properties for network adapters that have the name "Ethernet".
Command: Get-OSCNetAdapterProperty -Name "Ethernet" -AllProperties
Screenshot:

Example 6: Gets specified network adapters properties and advanced properties. If AllProperties parameter is specified, advanced properties can also be filtered either by DisplayName or RegistryKeyword.
Command: Get-OSCNetAdapterProperty -AllProperties -Property "Name","Jumbo Packet","*JumboPacket","DriverVersion"
Screenshot:

Example 7: Gets the specified network adapter’s properties and advanced properties, and then exports the result to a .CSV file.
Command: Get-OSCNetAdapterProperty -AllProperties -Property "Name","FullDuplex","Jumbo Packet","DriverVersion" | Export-Csv C:\Scripts\041\results.csv -NoTypeInformation
Screenshot:

Example 8: Gets specified network adapters properties and advanced properties from different computers by using the Invoke-Command cmdlet. Before running the Invoke-Command cmdlet, you should add the command that you want to run to the end of the script file.
Command: Invoke-Command -ComputerName computer01,computer02 -FilePath C:\Scripts\041\GetNetAdapterProperty.ps1 | Select PSComputerName,ifAlias,DriverVersion,LinkLayerAddress
Screenshot:

 

Additional Resources

Technical Resources:
Windows PowerShell Advanced Function
Get-NetAdapter
Get-NetAdapterAdvancedProperty