How to Set DNS Suffix and Registration using PowerShell

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:

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.

15 thoughts on “How to Set DNS Suffix and Registration using PowerShell”

  1. Pingback: SCCM Application Detection Method for Network Adapter Configuration | BorisKagan.net

  2. 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.

  3. 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

  4. 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

  5. Is it possible to apply this command to all network adapters or individually named network adapters rather than the one currently pulling ip?

  6. 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”?

    1. get-netadapter | where {$_.name -ne “Local Area Connection”}| foreach{
      write-host $_.name
      Set-DnsClient $_.name -ConnectionSpecificSuffix “workstation.blah.ca” -UseSuffixWhenRegistering $TRUE
      }
      ipconfig /registerdns

  7. 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.”?

  8. Real Genius Fan

    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
    }
    }
    }
    }

  9. 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.

  10. Pingback: Configure Autodesk Desktop Connector to maintain login session on Citrix non-persistent VMs - My little Farm

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.