Trying to set DNS Suffixes that are entered as a parameter into my script. Found that there is a registry key - HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\SearchList
and can set them in there but, as the parameters are passed as UK.COM,US.COM,AUS.COM,NL.COM
.
The problem is that when I look at the registry key it is removing each comma between the domains.
I found a fix here: Powershell is removing comma from program argument
However, the answer states to put the paramters in quotes - the problem is that the parameter is being read from an external system (which I cannot change) and the line for where it gets this from is this:
<Param><ParamValue>UK.COM,US.COM,NL.COM</ParamValue></Param><Param>
So, how can I keep the comma when this is being passed in?
The input being entered is this (getting rid of the IP's and leaving just the DNS search order):
.\ip_assign.ps1 ip subnet gateway dns_servers dns_domain UK.COM,US.COM,NL.COM pri_wins sec_wins
Script (look at parameter 6)
param (
[Parameter(Mandatory=$true,
Position = 1)]
[string]$IP
,
[Parameter(Position = 2)]
[string]$SubnetMask = "none"
,
[Parameter(Position = 3)]
[string]$Gateway = "none"
,
[Parameter(Position = 4)]
[string[]]$DNSServers
,
[Parameter(Position = 5)]
[string[]]$DNSDomain
,
[Parameter(Position = 6)]
$DNSSuffixs
,
[Parameter(Position = 7)]
[string[]]$PrimaryWINS
,
[Parameter(Position = 8)]
[string[]]$SecondaryWINS
)
$TeamAdaptor = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where-Object { $_.Caption -ilike '*Virtual*'}
$TeamAdaptor.EnableStatic($IP,$SubnetMask) | Out-Null
$TeamAdaptor.SetGateways($Gateway) | Out-Null
$TeamAdaptor.SetDNSServerSearchOrder($DNSServers) | Out-Null
$TeamAdaptor.SetDNSDomain($DNSDomain) | Out-Null
$TeamAdaptor.SetWINSServer($PrimaryWINS,$SecondaryWINS) | Out-Null
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters" -Name "SearchList" -Value $DNSSuffixs