Update DNS static servers in your local Network

 lets say you need to update your DNS servers, maybe you installed a new Domain Controller in your network. So probably the last step is update in each computer the primary and secondary DNS server.

It's sad, but in GPO, you will not find an effective way of doing this for windows10

Instead, you can use this script.

$inet1=Get-DnsClient  | Get-DnsClientServerAddress | where{$_.ServerAddresses -contains "" -or $_.ServerAddresses -contains ""}
foreach($nic in $inet1){
    Set-DnsClientServerAddress -InterfaceIndex $nic.InterfaceIndex -ServerAddresses ("","")

You can change the old IPs ( and for new IPs.

then, save the file as ChangeDNS.ps1 file in your network Share.

Create a New GPO and configure the Schedule Tasks for the Computer node.

Configure the task as Immediate Task.

Set the user account as SYSTEM. It will automatically convert into NT Authority\system.

Set the check "run with highest privileges"

In the Actions tab, create a new "Start a program" action.

Set the Program as:


Set the Add Arguments point to this line, and modify including your network share and file:

-ExecutionPolicy Bypass -command "& \\NETWORKSERVER\scripts\CambioDNS\CambioDNS.ps1"

Finally, set the following in common Tab.

"Apply once and do not reapply"

With this settings, the GPO will change the IP address of DNS servers in all computers.


  1. Thank you. It's great script. But this script ask confirmation. How can I automatically answer?


Post a Comment

Popular posts from this blog

Powershell Scritp for Inventory VMS in Hyper-V and VMware

Error 'General access denied error' (0x80070005). Starting SCVMM Resource