Wednesday, August 21, 2019

Set-DnsClientServerAddress - PowerShell Cmdlet of the Week

Next up in this series is a cmdlet I use quite often:

Set-DnsClientServerAddress

This cmdlet is especially useful when you need to statically assign the DNS servers that a client will use, and, in what order they will attempt to use them. My usual use case for this is in my lab environment where almost all of the servers have statically assigned IP address and DNS servers.

If you'd rather watch me demo this, there's a short video on TechSnips that also describes this cmdlet.
How To Set The DNS Server Search Order On Windows With PowerShell

So, to get started, let's take a quick look at the current list of DNS servers.

Along with Get-DnsClientServerAddress, we'll use the parameter -AddressFamily IPv4 allowing us to specify that we only want to see the IPv4 addresses. To see both IPv4 and IPv6, we would simply omit this parameter.


As we can see here, there are currently two DNS servers listed here. What we're going to do, is change the order of the original two, and add a third DNS server that was just recently brought online. To do this, we'll enter:

Set-DnsClientServerAddress -InterfaceIndex 10 `
-ServerAddresses 192.168.2.32,192.168.2.31,192.168.2.56

To break down this list of Parameters:
-InterfaceIndex 10
     - We use this to specify the interface. This info comes from the previous command

-ServerAddresses 192.168.2.32,192.168.2.31,192.168.2.56
     - A comma-separated list of our DNS servers, in the desired order.

One important note: Be sure to type in all of the DNS server addresses into this cmdlet, as it does not append to the existing list, it replaces it completely.

To confirm this worked, we'll just use Get-DnsClientServerAddress one more time:


There it is, our DNS server list has been modified as we expected.

That's all there is to it!

No comments:

Post a Comment