Powershell: automatically collects nic pci bus information

Source: Internet
Author: User

When you deploy a Hyper-V cluster, it is painful to configure the network. Different vendors or changed hardware la s are only two examples of challenges for automated deployment. In this article, I will share with you how PowerShell collects information about which network adapter is located on what PCI bus. You can use this information to rename the network adapter, combine and change the network adapter settings.

We start by collecting information about existing network adapters. The PowerShell command to complete this process is as follows:

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

The result is shown in:

In the output, we find the network adapter location. You may think that if the server has 12 network adapters, it is not practical. Then we can add | ft Location in this PowerShell command to collect PCI bus information.

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

Now we have all the network adapters in the server, but which one is it?

What we need is the adapter name, such as the task manager. The following command will give you the information. It is also not applicable to all adapters.

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

Let's put the first command into the variable and execute a loop on the second command. To display the result, we will make a simple Write-Host to display the output. The script is displayed as follows:

$ 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

}

What will happen? Let's take a look!

This is the case. I also added the MAC address and GUID. The macaddress in this example is also used together with the bacscli.exe command line tool of the official website to configure network adapter settings. If needed, GUID can be used to add TcpAckFrequency to the Registry.

Copy and paste to ensure that all single double quotation marks are correct. I hope this article will be useful to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.