Link to home
Start Free TrialLog in
Avatar of Fady AbuZuaiter
Fady AbuZuaiterFlag for Qatar

asked on

Replace DNS Server by Batch File

Hello,

I'm changing the DNS Servers on our Environment to new IPs. i found a batch script which worked perfectly on the Servers that have one connection only but for the servers that have two it didn't worked as it some time change the DNS for the correct one and some time no.

how i can modify it to change the DNS for the network interface that have the old IPs or that Connected to the Domain.

below is the script & I want it as batch to deploy it by SCCM

@echo off
set dnsserver=10.10.1.3
set dnsserver2=10.10.1.4

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
 

Exit
 )
)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ben Personick (Previously QCubed)
Ben Personick (Previously QCubed)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial