How to Set the DNS Server Search Order on Windows with PowerShell

To follow along, you can find a copy of the code used in the SnipSnips GitHub repo.

Setting your DNS server search order with PowerShell is actually really easy. We’ll start with the Get-DNSClientServerAddress to get a look at our existing settings as you can see below.

So there you can see, we have our existing settings on ethernet interface index seven, and our addresses are 192.168.2.52 and the secondary server is at .51.


Are you an IT pro ready to take your career to the next level? If so, join our contributor program! You don't have to be an expert presenter, a Microsoft MVP or even have a blog. We want your knowledge! You will be coached on presentation skills, become a member of our awesome community and get paid some nice side hustle income every, single month! Sign up today!.

So we’ll do a quick nslookup to file01.corp.ad, to verify that our primary is in fact responding.

So there we go, you can see above that a responding DNS server is our primary at .52, and successfully returned .55 is our file server.

Now, let’s change the order of our DNS servers. To do that, we’ll use the Set-DNSClientServerAddress cmdlet. We’ll point it to interface index seven as listed above, and I’ll change our order, so 192, 168.2.51 is our primary, and .52 is now our secondary.

We’ll do a quick verification. I’ll check interface index seven.

There, now you can see above, .51 is now our primary as it’s listed first, and .52 is our secondary.

Do another quick nslookup, and you can see that that now returns from .51, which is our primary DNS server.

Adam Bertram is a 20-year veteran of IT and experienced online business professional. He’s an entrepreneur, IT influencer, Microsoft MVP, blogger, trainer and content marketing writer for multiple technology companies. Adam is also the founder of the popular IT career development platform TechSnips.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.