none
Name Network Interfaces by PCI Bus ID

    Pertanyaan

  • I am trying to figure out a way to automatically assign names to network interface card ports by the PCI bus ID information. I found this post on how to get said information so I can correctly identify a particular network interface that carries the same hardware configuration on a particular server. I am trying to leverage this information to assign connection names and possibly IP addresses as well. Can anyone think of how to this would be possible?

    http://get-powershell.com/post/2010/04/07/Pull-PCI-Bus-information-for-Network-Cards-with-PowerShell.aspx

    Thanks.


    10 Februari 2012 0:55

Jawaban

Semua Balasan

  • Are you just trying to determine how to set the connection names? If so you might want to take a look at this: http://poshcode.org/1452.

    10 Februari 2012 1:31
    Moderator
  • That seems to be on the right track, but I need something that pulls PCIBusID, PCIDeviceID,PCIFunctionID and let's me assign a specific value to replace "Local Area Connection" on each adapter with a custom value depending on the three discovered variables.


    10 Februari 2012 2:55
  • Hi,

    You should be able to combine the information in both of those scripts to accomplish what you need.

    Bill

    17 Februari 2012 22:36
    Moderator
  • Hi,

    You should be able to combine the information in both of those scripts to accomplish what you need.

    Bill

    Bill the problem with both of those scipts is that they don't work and could never have worked.

    The methods only work on Vista and later.


    ¯\_(ツ)_/¯

    17 Februari 2012 23:01
  • Hi,

    Of course there will be some modifications needed for down-level OSes. The OP didn't specify which platform(s).

    Bill

    17 Februari 2012 23:05
    Moderator
  • Hi,

    Of course there will be some modifications needed for down-level OSes. The OP didn't specify which platform(s).

    Bill

    Also no one notes that most of the code for that method is missing.  The site is almost dead with most blogs being abandoned almost a year ago.


    ¯\_(ツ)_/¯

    17 Februari 2012 23:19
  • Why you don't use Mac Address to identify the network cards? Mac Address is not enough?

    I think Marc link is suitable for your need..


    Gastone Canali >http://www.armadillo.it


    18 Februari 2012 18:25
  • All,

    We are trying to do this on Server 2008 R2. It is the only platform we care about so powershell is definitely usable. I found a script that will rename the network interfaces to their mac address and it works fine, but it isn't what we are looking for. We deploy large numbers of servers with a specific hardware configuration. These servers have 6 network interfaces that all have a set purpose when we setup infrastrucuture. Host Lan, iSCSIA, iSCSIB, Replication, VM Guest Lan, etc. Naming these connections manually on a hundred servers can definitely take a good amount of time.

    We worked with one of our programmers and came up with the script below. The script works on the add-in dual interface network card, but not the embedded onboard broadcom nics. I believe the reason it fails renaming those is because the WMI call to PnPSignedDriver has two entries for each interface i.e. (PCI bus 1, device 0, function 0), because there are two entries for two differenct driver version even on a base Server 2008 R2 OS instlall . PCI1A and PCI1B are renamed successfully since they only have one reference (PCI bus 4, device 0, function 1).

    function Set-NicName($newName, $location){
        $nicInfo = (Get-WMIObject Win32_PnPSignedDriver | ?{$_.Location -eq $location}).DeviceID
        $nic = Get-WMIObject Win32_NetworkAdapter | ?{$_.PNPDeviceID -eq $nicInfo}
        if ($nic){
            $nic.NetConnectionID = $newName
            $nic.Put()
        }
    }

    $nicNames = @{
    "OB1-HostLAN" = "PCI bus 1, device 0, function 0";
    "OB2-iSCSI-A" = "PCI bus 1, device 0, function 1";
    "OB3-Replication" = "PCI bus 2, device 0, function 0";
    "OB4-Unused" = "PCI bus 2, device 0, function 1";
    "PCI1A-GuestLAN" = "PCI bus 4, device 0, function 0";
    "PCI1B-iSCSI-B" = "PCI bus 4, device 0, function 1"
    }

    $nicNames.Keys | % {
        Set-NicName $_ $nicNames[$_]
    }

    This is another script we are trying to leverage to get this accomplished..

    Function Get-NicBusFunctionID {
    $adapters = get-wmiobject win32_networkadapter -filter "netenabled=true"

    foreach ($adapter in $adapters) {
           
            $deviceId = $adapter.PnPDeviceID
            $locationInfo = (get-itemproperty -path "HKLM:\SYSTEM\CurrentControlSet\Enum\$deviceID" -name locationinformation).locationINformation
            
            $businfo = Resolve-PCIBusInfo -locationInfo $locationinfo
            
            new-object psobject -property @{
                "Name"        = $adapter.NetConnectionID;
                "MacAddress"  = $adapter.MacAddress
                "Index"       = $adapter.Index;
                "PCIBusID"      = $businfo.BusID;
                "PCIDeviceID"   = $businfo.DeviceID;
                "PCIFunctionID" = $businfo.FunctionID
            }
    }

    }

    Function Resolve-PCIBusInfo {

    param (
    [parameter(ValueFromPipeline=$true,Mandatory=$true)]
    [string]
    $locationInfo
    )
    PROCESS {
    [void]($locationInfo -match  "\d,\d,\d")
    $busId,$deviceID,$functionID = $matches[0] -split ","

    new-object psobject -property @{
              "BusID" = $busID;
              "DeviceID" = "$deviceID"
              "FunctionID" = "$functionID"
              }
    }         
    }




    22 Februari 2012 19:43
  • Hi,

    It sounds like you will need to work with your internal developer(s) to resolve your issue. Since we don't have your specific configuration we can't just write a custom-tailored script that will work for you.

    Bill

    22 Februari 2012 21:15
    Moderator
  • Hi,

    It sounds like you will need to work with your internal developer(s) to resolve your issue. Since we don't have your specific configuration we can't just write a custom-tailored script that will work for you.

    Bill

    What specifcs would someone need? In the end we need the interfaces at these PCI locations to be given these names.

    "OB1-HostLAN" = "PCI bus 1, device 0, function 0";
    "OB2-iSCSI-A" = "PCI bus 1, device 0, function 1";
    "OB3-Replication" = "PCI bus 2, device 0, function 0";
    "OB4-Unused" = "PCI bus 2, device 0, function 1";
    "PCI1A-GuestLAN" = "PCI bus 4, device 0, function 0";
    "PCI1B-iSCSI-B" = "PCI bus 4, device 0, function 1"

    22 Februari 2012 21:18
  • Hi,

    It looks like you already have a good working definition of what you need to do. You will need to do this in-house as we can't test and we can't see your screen. The script will have to be developed for your specific environment (and it looks like you're almost there anyway).

    Bill

    22 Februari 2012 22:31
    Moderator