PowerShell – Add DNS Suffix to Ethernet Connections

email me

# SUFFIX TO ADD
$Domain = 'YourDomainHere.com'

# ONLY RETURN ETHERNET CONNECTIONS
$Nic = Get-DnsClient | Where-Object -Property InterfaceAlias -Match Ethernet

# ADD SUFFIX TO EACH ETHERNET CONNECTION
Foreach ($N in $Nic) {
	Set-DnsClient -ConnectionSpecificSuffix $Domain -InterfaceIndex $N.InterfaceIndex
	$Alias = $N.InterfaceAlias
	$Index = $N.InterfaceIndex
}

 

 

Notes


Get-DnsClient

Set-DnsClient

Set-DnsClientGlobalSetting

Get-DnsClientGlobalSetting

Get-NetAdapter

 

Clear Suffix List

Set-DnsClientGlobalSetting -SuffixSearchList @(“”)

 

Set Suffix Order

Set-DnsClientGlobalSetting -SuffixSearchList @(“domain.com”, “child.domain.com”)

or

$DnsSuffixes = “domain.com”,”child.domain.com”
Invoke-Wmimethod -Class win32_networkadapterconfiguration -Name setDNSSuffixSearchOrder -ArgumentList @($DnsSuffixes),$null

 

Set Suffix for Single Network Connection

Get-NetAdapter | where {$_.name -ne “Local Area Connection”}| foreach{
Write-Host $_.name
Set-DnsClient $_.name -ConnectionSpecificSuffix “YourDomainHere.com” -UseSuffixWhenRegistering $TRUE
}
ipconfig /registerdns


Reg Keys for Domain Suffix

HKLM\System\CurrentControlSet\Services\TCPIP\Parameters\domain
HKLM\System\CurrentControlSet\Services\TCPIP\Parameters\NV domain

Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name ‘NV Domain’ -Value child.domain.com

Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name SyncDomainWithMembership -Value 0


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\ComputerName
 is the current NetBIOS computer name.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName is the NetBIOS computer name that will be used when the computer is restarted.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname is the host name of the computer.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname is the host name that the computer will take when it is restarted.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Domain is the current DNS domain name. Domain may be empty or not present. The full computer name is the values of Hostname + Domain.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Domain is the DNS domain name that the computer will use when it is restarted. The full computer name after a restart is the values of NV Hostname + NV Domain.