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 "192.168.0.245" -or $_.ServerAddresses -contains "192.168.0.207"}
foreach($nic in $inet1){
    Set-DnsClientServerAddress -InterfaceIndex $nic.InterfaceIndex -ServerAddresses ("192.168.0.245","192.168.0.114")
}


You can change the old IPs (192.168.0.245 and 192.168.0.207) 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:

c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

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.


Comments

Popular posts from this blog

Scripting sobre Backup de SQL y subida a FTP

HAFNIUM zero-day exploit Microsoft Exchange on-premises (02-march 2021)

Reclaim Disk Space from Shadow Copies