How to make the registry value inserted in turn when setting the binding order?

I am trying to set the NIC binding order. I made the code below that goes through the network cards that I want in the order I need. The registry key must accept all network cards, otherwise it will not work, and the key must be installed on MULTI_SZ.

The problem is that when I combine all the GUIDs for $Combine, it does not split each GUID in turn and instead displays it in one big long line. I put `n at the beginning of each GUID so that they enter a string, but it still doesn't work.

The result $Combinelooks great and displays it in the order I want, however, when they are placed in the registry key, this is one big line (see screenshot below)

\Device\{2533855F-2A59-485D-87A0-167E5DA39E45}
\Device\{B7883140-E15B-4409-BA1B-96E37A45425C}
\Device\{1FE01120-3866-437F-81FF-556B08999AA4}
\Device\{4A208C06-0D99-4DE4-9B2F-86285AEF864E} 
\Device\{D129DDA8-C64B-46A1-B99A-EA74FC4FAF81} 
\Device\{2A6471FB-C1D6-47D2-A665-9F276D142D7C} 
\Device\{D5C9183B-E542-4010-866F-4443AD55F28C} 
\Device\{306D2DED-18B5-45D8-858E-BB3F49E3BD6A} 
\Device\{30EF50B2-E4B3-400D-9614-B590E37DE4D8}

So the question is, how can I get the results to display line by line?

the code:

$TeamConnection = Get-WmiObject -Class win32_networkadapter | where {$_.Netconnectionid -ne $null -and $_.NetconnectionID -eq "Team"} | select -ExpandProperty GUID
$Prod1Connection = Get-WmiObject -Class win32_networkadapter | where {$_.Netconnectionid -ne $null -and $_.NetconnectionID -eq "Prod1"} | select -ExpandProperty GUID
$Prod2Connection = Get-WmiObject -Class win32_networkadapter | where {$_.Netconnectionid -ne $null -and $_.NetconnectionID -eq "Prod2"} | select -ExpandProperty GUID
$EverythingElse = Get-WmiObject -Class win32_networkadapter | where {$_.Netconnectionid -ne $null -and $_.NetconnectionID -ilike "Local*"} | select -ExpandProperty GUID

$device = "\Device\"
$First_isTeam = "$($device)$($TeamConnection)"
$Second_isProd1 = "$($device)$($Prod1Connection)"
$Third_isProd2 = "$($device)$($Prod2Connection)"

$Total = "$($First_isTeam)`n$($Second_isProd1)`n$($Third_isProd2)"

$NotMembers = $EverythingElse | ForEach-Object { "`n$($device)$($_)" }

$Combine = "$($Total)$($NotMembers)"
$Combine
Set-Location -path "HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Linkage"; Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Linkage" -Name "Bind" -Value $Combine -Type MultiString

Screenshot with output (WRONG):

enter image description here

Screenshot of how it should look (WORK):

enter image description here

Also noticed one more thing: when I selected all the GUIDs, there are spaces at the end of each GUID .... I think this may be a problem. I can’t understand how I add them:

ROOMS: enter image description here

+4
source share
1 answer

Multi-line data should be added as an array, not as a single line.

$Combine = $First_isTeam, $Second_isProd1, $Third_isProd2
$Combine += $EverythingElse | ForEach-Object { "$device$_" }

Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Linkage' `
  -Name 'Bind' -Value $Combine -Type MultiString
+4
source

All Articles