none
PowerShell -> change NIC adapter binding order?

    Question

  • Windows 7 x86/x64 (PowerShell or VBScript)

    Looking for a script that can change the network adapter binding order. Ideally, this will run immediately after sysprep, with no user interaction.  Would anyone know of a good method?

    Monday, May 10, 2010 7:08 PM

Answers

  • One way is to modify the following registry key directly and then reboot, this does require some work to programmically figure out the NIC GUIDs used in setting, but that info is availabe via WMI.

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind

    The Bind registry value is a multi-string value that contains a list of network adapters in binding order. The first entry in the list is the first bound network adapter; the second entry is the second network adapter in the binding order; and so forth.

    Otherwise, you need see if WMI or PS can reorder without an reboot.  Of course .NET is probably the best choice for this type of thing. 

    Note:

    The value for the SettingsID key from Win32_NetworkConfiguration is a GUID that represents a unique network adapter.
    The Win32_NetworkAdapter WMI class can be queried to determine which network adapters are being used.

     

    Monday, May 10, 2010 7:36 PM

All replies

  • One way is to modify the following registry key directly and then reboot, this does require some work to programmically figure out the NIC GUIDs used in setting, but that info is availabe via WMI.

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind

    The Bind registry value is a multi-string value that contains a list of network adapters in binding order. The first entry in the list is the first bound network adapter; the second entry is the second network adapter in the binding order; and so forth.

    Otherwise, you need see if WMI or PS can reorder without an reboot.  Of course .NET is probably the best choice for this type of thing. 

    Note:

    The value for the SettingsID key from Win32_NetworkConfiguration is a GUID that represents a unique network adapter.
    The Win32_NetworkAdapter WMI class can be queried to determine which network adapters are being used.

     

    Monday, May 10, 2010 7:36 PM
  • Hi,

    I gave this a go.

    I found that to ascertain what the GUID's were related to I had to look under classes (2 examples below)

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0010

    I read DriverDesc and extracted the relevant NetCfgInstanceId to get the required GUID.

    I then was able to goto HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind and see the relevant GUIDs (and some less so (for me) - such as the firewire etc.

    I modified the order of the bind field to suit what I wanted and rebooted the machine.  When I restarted, the GUID interface showing the bindings hadn't changed.  However, I was able to confirm that the order of the GUIDs under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage\Bind were what I wanted them to be.

    So I assume that the binding order didn't change.

    I then thought about looking at the Interfacemetric to see if I could manually change the "cost" of the interfaces to enforce what I wanted.  Essentially, make VPN the cheapest route, followed by LAN, followed by WAN and then whatever else.

    On a different machine I went to

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\GUID and added a field - InterfaceMetric and gave costings.  I deliberately kept the ones I cared about very low for the sake of the testing.  Essentially, vpn = 7, LAN = 8, WAN = 9 and put the others up much higher. 

    I rebooted and confirmed that the interface values were pushed into the network cards under IP advanced metric etc.

    However, when I went back to the bindings GUI, again the order hadn't changed.

    Thinking I would go out of scripting, I went to another machine and manually entered metrics into the GUI for the interfaces.  I rebooted the machine and went to the bindings GUI and again it hadnt changed.  Going back to the network interfaces I was able to confirm that the metric was statically assigned.

    Am I missing something simple or is it possible that the GUI doens't update?

    An example of the Bind before modification

    \Device\{FAB44157-AE42-4CAE-B1E3-0B3660549E73}|\Device\{267686AB-CE2D-47C5-946A-FF98F9AF6719}|\Device\{8BA22ABF-83F4-4A6C-842D-383048EEF252}|\Device\{4FB30230-F923-40BB-AE4E-732336527E3C}|\Device\{0A44126F-64D8-475E-9531-F23C54A29061}|\Device\NdisWanIp|

     

    what it became after update

    \Device\{FAB44157-AE42-4CAE-B1E3-0B3660549E73}|\Device\{0A44126F-64D8-475E-9531-F23C54A29061}|\Device\{4FB30230-F923-40BB-AE4E-732336527E3C}|\Device\{267686AB-CE2D-47C5-946A-FF98F9AF6719}|\Device\{8BA22ABF-83F4-4A6C-842D-383048EEF252}|\Device\NdisWanIp|

     

     

    Wednesday, August 11, 2010 4:41 AM
  • First try editing the BIND setting by hand and verify everyting works as expected when done manually.  This will help determine if its a programming or procedure issue.

    When editing with a script note that the Bind, Route and Export key’s contain a list of NIC’s separated by a NULL (\0).  You may need to figure out if are using the correct character for your scripting language.

    Verify the GUID you are using is correct using this command.

    wmic nicconfig get Description,SettingID

    Read this post for more information that may help you.

    http://social.technet.microsoft.com/Forums/en-US/winservercore/thread/94bd0b5f-58fe-4ff7-9ffe-8f5ad97ac0fd

    Thursday, August 12, 2010 3:38 PM
  • It looks like there is a VB script to change the binding order http://support.microsoft.com/kb/894564?wa=wsignin1.0

    I don't know how to convert it to PowerShell through.  Anyone have any ideas suggestions on that?



    ==== snip - Start of script code Set_Wireless_NIC_IPMetric.vbs script ====
    On Error Resume Next

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    regValueDataMetric = "35"

    Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapter Where NetConnectionID = 'Wireless Network Connection'")

    For Each objItem in colItems
    strMACAddress = objItem.MACAddress
    Wscript.Echo "MACAddress: " & strMACAddress
    Next

    Set colNetCard = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

    For Each objNetCard in colNetCard
    If objNetCard.MACAddress = strMACAddress Then
    For Each strIPAddress in objNetCard.IPAddress
    Wscript.Echo "Description: " & objNetCard.Description
    Wscript.Echo "IP Address: " & strIPAddress
    Wscript.Echo "IPConnectionMetric: " & objNetCard.IPConnectionMetric
    objNetCard.SetIPConnectionMetric(regValueDataMetric)
    Next
    End If
    Next
    ==== snip - End of VBS script ====
    Wednesday, December 12, 2012 10:22 PM
  • First, this is not a free code-translation service but rather a forum where we do our best to answer specific questions.

    Second, why translate the script from VBScript to PowerShell if it works now?

    Third, this question is already marked as answered. If you still need help, please start a new question.

    Bill

    Wednesday, December 12, 2012 10:26 PM
  • What about the export and the route key under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Linkage, should these be changed as well ?
    Thursday, February 06, 2014 11:39 PM