Although I had written this script around 4 years back I have again revised it to work it in more better way with status report on console. I used this script again after long time to change/update DNS ip addresses on remote Windows servers, after introducing my new upgraded DNS servers. Same task I performed but this time to replace DNS ips on an average 6000 remote windows servers. As it can be seen in below screenshot, There are 2 Nics In my environment, on all the server and I wanted to change DNS IPs on physical adapter with name Ethernet only.

If you check on windows 2012 and above server OS, physical network adapter is named as Ethernet by default, unless it is modified.

Copy script in the Set-DnsIP.ps1 file, I have kept file on root c:\ drive. Run Set-ExecutionPolicy Unrestricted, so ps1 scripts are allowed to execute. Next by running below command I will replace existing DNS IPs and it also verify it and shows result on console. For simplicity I am running this command directly from domain joined server logged in with domain admin username and password, So there is no requirement to mention credentials.

.\Set-DnsIP.ps1 -Name DSC01 -NetworkName Ethernet -DnsIPs @('192.168.33.5','192.168.33.6')

PARAMETERS

-Name = Put computername here

-NetworkName = Type network physical adapter name here which is found under network connections, in most of the cases it will named as Ethernet.

-DnsIP = here you can put multiple ip in array with @()

-Protocol = This is optional and Dcom (Remote procedure call - RPC) or WSman (Windows Powershell remoting need to be enabled) can be used here. By default it connects using Dcom and does not require any special configuration.

-Credential = This is another optional parameter and here you can add credentials to connect remotely or locally.

Another way of performing same task on multiple system, Here in below example I am fetching computer names from active directory domain controller and updating IP on those servers with foreach loop.

Get-ADComputer -Filter * | foreach {.\Set-DNSIP -Name $_.Name -NetworkName Ethernet -DnsIPs 192.168.33.11}

In the last if you have list of servers in plain text file replace Get-Adcomputer -filter * with cat filename.txt. This script is based and built using CIM cmdlets.

to use different username and password credentials than the logged in user, use parameter -credential, it will popup for username and password.

.\Set-DnsIP.ps1 -Name DSC01 -NetworkName Ethernet -DnsIPs @('192.168.33.5','192.168.33.6') -Credential