HOWTO: Remotely change DNS settings


Betweentimes you need to update multiple computers with DNS settings. Instead of doing this one by one manually you can automate it so it can be done in one go, from a plain PowerShell script. It's simple but very effective. This article shows how to remotely change DNS settings.


1. Start Windows PowerShell:

   - Click Start, type PowerShell, and then click Windows PowerShell.

2. Use this simple script to set the DNS server IP addresses on a network card based on its name:

   - function Set-DnsServerIpAddress {
param(
[string] $ComputerName,
[string] $NicName,
[string] $IpAddresses
)
if (Test-Connection -ComputerName $ComputerName -Count 2 -Quiet) {
Invoke-Command -ComputerName $ComputerName -ScriptBlock { param ($ComputerName, $NicName, $IpAddresses)
write-host "Setting on $ComputerName on interface $NicName a new set of DNS Servers $IpAddresses"
Set-DnsClientServerAddress -InterfaceAlias $NicName -ServerAddresses $IpAddresses
} -ArgumentList $ComputerName, $NicName, $IpAddresses
} else {
write-host "Can't access $ComputerName. Computer is not online."
}
}

3. The using is so simple:

   - # Where $ServerName (set as you need)
# Where Service (name of the Network Card (takes wildcard))
# Where IpAddresses (in brackets)
Set-DnsServerIpAddress -ComputerName $ServerName -NicName "Service*" -IpAddresses '8.8.8.8','8.8.4.3','8.8.8.2'

Also consider using Action1 to remotely change DNS settings if:
- You need to perform this action on multiple (hundreds or even thousands) computers simultaneously.
- Some of your endpoints are laptops not connected to corporate network at all times.

Action1 is a cloud-based platform for software deployment, software/hardware inventory, patch management, endpoint configuration and more. It is free with basic functionality.


Other Relevant HOWTOs: