When doing a deployment of a Hyper-V cluster consequently configuring the networking can be a pain in the you know what. Different vendors or changing hardware layouts are only two examples that can make automated deployment challenging. This blog will explain how you can collect information about which network adapter is located at what PCI bus with Powershell. This information you can then later use to rename network adapter, teaming, changing network adapter settings etc etc.

Let first start by collecting some information of the present network adapters. The Powershell command to do this is something like this:

Get-WMIObject Win32_PNPSignedDriver | where { $_.DeviceClass -eq “NET” -and $_.HardWareID -like “*PCI*”}

The result will look something like shown below:

1

In the output we can find the location of the network adapters. You probably can imagine when having 12 network adapters in your server this isn’t very useful. So lets only collect the PCI bus information by adding | ft Location to the Powershell command.

Get-WMIObject Win32_PNPSignedDriver | where { $_.DeviceClass -eq “NET” -and $_.HardWareID -like “*PCI*”} | ft Location

2

So now we have all the Location of the network adapters present in the server but which is which?

What we need is the Adapter Name as shown in for example the Task Manager. With the command shown below you will get this information. Again for all adapters. Not very useful.

Get-WMIObject Win32_NetworkAdapter | where { $_.PNPDeviceID -eq $Adapter.DeviceID }

Let’s put the first command in a variable and do a loop with the second command. To display the results we do a simple Write-Host to show the output. The script will then look like this.

$Adapters = Get-WMIObject Win32_PNPSignedDriver | where { $_.DeviceClass -eq “NET” -and $_.HardWareID -like “*PCI*”}

foreach ($Adapter in $Adapters ) {

$AdapterName = Get-WMIObject Win32_NetworkAdapter | where { $_.PNPDeviceID -eq $Adapter.DeviceID }

Write-Host ‘Adapter Name :’ $AdapterName.NetConnectionID

Write-Host ‘PCI BUS :’ $Adapter.Location

Write-Host ‘MAC Address :’ $AdapterName.MACAddress

Write-Host ‘GUID :’ $AdapterName.GUID

Write-Host

}

The result? Look below. Smile

image

And voila. I added also the MAC address and the GUID. The MAC address for instance cab be used in combination with Broadcom’s BACScli.exe command line utility to configure network adapter settings. The GUID can be used to add the TcpAckFrequency to the registry if needed.

When copy paste make sure all single and double quotes are correct.

Hopefully you’ll find this blog post useful. Have fun with it!