We are upgrading our DNS servers and need to change all static IP clients to point to the new DNS servers.
- Change only the adapters that are named similar to "Local Area Connection". I say similar because some adapters are named "Local Area Connection" and others have numbers suffixed similar to "Local Area Connection 5". Some clients have dual NICs. Some clients have VMware Network Adapters.
- Change only the clients whose Local Area Connection is set to static IP.
I have tried it with the code below and it doesn't work reliably. It works only on the explicit adapter name and rather annoyingly, it goes through the For statement for every positive hit. In my case, it cycled through four times since I have four NIC cards (two physical and two VMWare).
for /f "tokens=2 delims==" %%F in ('wmic nic where "NetConnectionStatus=2 and AdapterTypeId=0 and NetConnectionID like 'Local Area Connection'" get NetConnectionID /format:list') do set nicName=%%F
if "%nicName%" NEQ "" goto setDNS
for /f "tokens=3" %%a in ('netsh interface ip show config ^| find /i "DHCP Enabled"') do ( stuff )
My environment is Win7 and Active Directory 2008 transitioning to AD 2012.
I'm wondering if there is a better and more reliable method?