Windows Server 2016.
All Servers in domain obtain IP address automatically and DNS addresses are set manually:
Primary DNS 172.16.0.1
Secondary DNS 172.16.0.2
I created a 3rd DC (172.16.0.3), and moved FSMO roles.
I want to change the primary DNS on all servers (about 50) to the new DC 172.16.0.3.
I created a batch file with the following script:
@echo off
set dnsserver=172.16.0.3
set dnsserver2=172.16.0.1
for /f "tokens=1,2,3*" %%i in ('netsh interface show interface') do (
if %%i EQU Enabled (
rem echo change "%%l" : %dnsserver%
netsh interface ipv4 set dnsserver name="%%l" static %dnsserver% both
netsh interface ipv4 add dnsserver name="%%l" %dnsserver2% index=2
)
)
Then I created a GPO and linked it to the domain.
Computer configuration | Policies | Windows Settings | Scripts | (Startup\Shutdown) | Choose Startup In Scripts properties, I added the batch file.
In Security Filtering for this Group Policy I keep the Authenticated Users, add Domain Admins Group and some servers to test it. (Note: Authenticated Users includes all groups and users and computers, so the adding servers and Domain Admins is unnecessary).
I logon to these servers run gpupdate /force
but with no luck, GP is not applying the script.
I need to change the DNS IPs on all servers with no restart or logon.
Note: Script is correct, I run it manual as admin and it changes the DNS IPS.