This very simple PowerShell script can be used to set these options:
- DNS Suffix for this connection
- Register this connection’s addresses in DNS
- Use this connection’s DNS suffix in DNS registration
I’ve seen many questions online on how to use a script to mark the two checkboxes in this “Advanced TCP/IP Settings” window.
So here is the very short and simple PowerShell script:
1 2 3 4 |
$networkConfig = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'" $networkConfig.SetDnsDomain("clients.ad.company.com") $networkConfig.SetDynamicDNSRegistration($true,$true) ipconfig /registerdns |
The first line gets the adapters with a valid IP address. The second line sets the “DNS suffix for this connection” field. The third line enables each of the two checkboxes – if you change one of the $true values to $false, it will uncheck the corresponding checkbox. Finally, the last line simply updates the new settings in DNS without the need to restart the machine or anything like that.
This script can be deployed by SCCM as a package or an application, for which you can use this application detection method.
Pingback: SCCM Application Detection Method for Network Adapter Configuration | BorisKagan.net
Works perfect, thanks so much! Was looking for days to find a way to do this. Most other tutorials just show how to set the “Append these DNS suffixes” list.
excellent tip!
Using Pure Powershell (5.0?), you can do:
Get-NetAdapter -Name “name_of_your_adapter” | Set-DnsClient -UseSuffixWhenRegistering $false
Get-NetAdapter -Name “name_of_your_adaptger” | Set-DnsClient -RegisterThisConnectionsAddress $false
Instead of -Name, you could use -InterfaceIndex too
To get the list of interfaces, use:
Get-NetAdapter
To add to my last remark: $false to turn off, $true to turn on 😉
Keep in mind you need to run PowerShell in admin mode. If you do not you will get a 91/90 code witch means it did not work. You should be looking for a Code 0. Worked like a charm. Thank you
Is it possible to apply this command to all network adapters or individually named network adapters rather than the one currently pulling ip?
This is great working little script, no issues when implemented correctly. However, I have massive a deployment projects, which requires each Network Adapter to have the same settings applied, regardless if the adapter is connected/live with an IP-Address. How would I go about having the other adapters configured exactly the same, even though they’re “Not Connected/No Connection”?
get-netadapter | where {$_.name -ne “Local Area Connection”}| foreach{
write-host $_.name
Set-DnsClient $_.name -ConnectionSpecificSuffix “workstation.blah.ca” -UseSuffixWhenRegistering $TRUE
}
ipconfig /registerdns
Nice script. What is the command to set “append primary and connection specific DNS suffixes” radio button and the check box “append parent suffixes of the primary DNS suffix.”?
Thanks so much. The GPO for this only worked for XP Pro
Set-DnsClient -InterfaceIndex 12 -ConnectionSpecificSuffix “corp.contoso.com”
https://docs.microsoft.com/en-us/powershell/module/dnsclient/set-dnsclient?view=win10-ps
Just incase anyone else has a headache from Win 10 21H2 setting a domain machine to public even though it is clearly part of a domain.
Function Fix-DNSSuffix {
if ((gwmi win32_computersystem).partofdomain -eq $true){
if (Test-ComputerSecureChannel -Repair){
Get-NetConnectionProfile | where {$_.NetworkCategory -eq “Public”} | foreach {
if ($_.InterfaceAlias) {
Set-DnsClient $_.InterfaceAlias -ConnectionSpecificSuffix $env:USERDNSDOMAIN -UseSuffixWhenRegistering $TRUE -ErrorAction SilentlyContinue }
ipconfig /registerdns
}
}
}
}
How would one set the SetDnsDomain and SetDynamicDNSRegistration on all physical adapters? The example shown will only change the settings on the current enabled device. All of my adapters are used depending on what I am working with, ie.. either a docking station, Wi-Fi or the internal adapter.
Pingback: Configure Autodesk Desktop Connector to maintain login session on Citrix non-persistent VMs - My little Farm