command to remove DNS entries in Advanced Settings?


  1. Posts : 3
    Win Server 2016
       #1

    command to remove DNS entries in Advanced Settings?


    Hi All

    Wondering if anyone knows a command to remove the DNS entries within the advanced TCP/IP settings?

    The primary and secondary DNS IP need to be changed with the tertiary and quaternary DNS IP. Simple enough doing it manually but there's over 50 VMs this needs to be done on so i'm trying to write a script for this.

    i did try to the below command but as the IPs are already added it wouldn't re-arrange them into the given order

    e.g. (IPs have been randomised)

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.56 1

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.57 2

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.55 3

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.54 4

    Any help is greatly appreciated - thanks
      My Computer


  2. Posts : 56,830
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #2

    rman91 said:
    Hi All

    Wondering if anyone knows a command to remove the DNS entries within the advanced TCP/IP settings?

    The primary and secondary DNS IP need to be changed with the tertiary and quaternary DNS IP. Simple enough doing it manually but there's over 50 VMs this needs to be done on so i'm trying to write a script for this.

    i did try to the below command but as the IPs are already added it wouldn't re-arrange them into the given order

    e.g. (IPs have been randomised)

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.56 1

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.57 2

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.55 3

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.54 4

    Any help is greatly appreciated - thanks
    Just a S.W.A.G really, but if you combine deletion and addition in the same .bat, it may work. Delete them all, then add in the order you want, one line each.



    netsh dnsclient delete dnsserver "Local Area Connection" all

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.56 1

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.201.57 2

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.55 3

    netsh dnsclient add dnsserver "Local Area Connection" 10.91.207.54 4
      My Computers


  3. Posts : 4,224
    Windows 10
       #3

    I agree with F14Tomcat, because the only way to control ordering is to provide the entries in the order you want. By removing all previous entries, you "make room" to add replacements in the desired order. If, for some odd reason or another, that doesn't work, you may want to look into using an automation tool like AutoHotkey instead to capture the sequence of GUI commands for removing and adding those entries instead. For what I hope are obvious reasons, the batch file is the preferred alternative.
    HTH,
    --Ed--
      My Computers


  4. Posts : 3
    Win Server 2016
    Thread Starter
       #4

    thanks very much for the replies - will give this ago and let you know!

    cheers
      My Computer


  5. Posts : 3
    Win Server 2016
    Thread Starter
       #5

    @f14tomcat @EdTittel

    FYI - with a little more looking around i've managed to find something that works. Thanks for your help!

    netsh dnsclient delete dnsserver "Local Area Connection" allnetsh interface ip set dns name="Local Area Connection" static 10.91.201.56netsh interface ip add dns name="Local Area Connection" 10.91.201.57 index=2netsh interface ip add dns name="Local Area Connection" 10.91.201.55 index=3netsh interface ip add dns name="Local Area Connection" 10.91.201.54 index=4
      My Computer


  6. Posts : 4,224
    Windows 10
       #6

    Good work. The text got all jammed together, but with my "parsing hat" on I think I see what you did. Good work. Now, you can try it as a script on one or two test machines. If that works, then it works, too.
    Persistence pays off once again!
    --Ed--
      My Computers


  7. Posts : 56,830
    Multi-boot Windows 10/11 - RTM, RP, Beta, and Insider
       #7

    rman91 said:
    @f14tomcat @EdTittel

    FYI - with a little more looking around i've managed to find something that works. Thanks for your help!

    netsh dnsclient delete dnsserver "Local Area Connection" allnetsh interface ip set dns name="Local Area Connection" static 10.91.201.56netsh interface ip add dns name="Local Area Connection" 10.91.201.57 index=2netsh interface ip add dns name="Local Area Connection" 10.91.201.55 index=3netsh interface ip add dns name="Local Area Connection" 10.91.201.54 index=4
    Very slick! Good job! Glad to see you got it!!
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:53.
Find Us




Windows 10 Forums