Skip to main content

How to Set DNS Suffix and Registration using PowerShell.

##
# How to Set DNS Suffix and Registration using PowerShell
# https://www.boriskagan.net/how-to-set-dns-suffix-and-registration-using-powershell/
#
# 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.
##

$networkConfig = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'"
$networkConfig.SetDnsDomain("clients.ad.company.com")
$networkConfig.SetDynamicDNSRegistration($true,$true)
ipconfig /registerdns


##
# Additional: SCCM Application Detection Method for Network Adapter Configuration
# https://www.boriskagan.net/sccm-application-detection-method-for-network-adapter-configuration/
##

#get only network adapters that have a valid IP address
$networkConfigStatus = Get-WmiObject Win32_NetworkAdapterConfiguration -filter "ipenabled = 'true'" | where { $_.ipaddress -like "192.168.*" }

#initial value
$valid = "TRUE"

#for every valid network adapter found (since some workstations can have dual NIC's)
for ($i=0; $i -lt $networkConfigStatus.Length; $i++) {
    #if each connection has the proper network config then do nothing
    if ($networkConfigStatus[$i].dnsdomain -like "clients.ad.company.com" -and
        $networkConfigStatus[$i].FullDNSRegistrationEnabled -like "True" -and
        $networkConfigStatus[$i].DomainDNSRegistrationEnabled -like "True") {

    } else {
        #if the config is wrong then change this to False
        $valid = "FALSE"
    }
}

#if no network adapters are found, report False
if ($networkConfigStatus.Length -eq 0) {
    $valid = "FALSE"
}

#if the value is still True, then write an output
if ($valid -like "TRUE"){
    Write-Host "Valid"
}