Powershell provides a quick and simple way to find the DNS server addresses on a client machine running the Windows operating system. We will look at the complete approach that can be used to find the DNS server address of a client machine using Powershell.
Here is our approach to getting the DNS server address for a client machine:
- We will find the network interface alias for which we need the DNS server address
- We will find the DNS server address for the interface alias using the Powershell cmdlet
To find the network interface alias for the network card, we will use the following command:
The output of this cmdlet will list all the network cards on the system. We will use the output to pick the network card and its interface alias.
The following screenshot shows the Get-DNSclient and its output. For our example, we will try to find the DNS Server address of the interface that is connected to the Wi-Fi network.
The interface alias that we are interested in is the Wi-Fi 2 network. Now that we know the interface alias, we will get to the next step of finding the DNS Server address associated with this network card.
Find DNS address
To find the DNS Server address on a Windows client machine, we will use the following Powershell command:
Get-DnsClientServerAddress -InterfaceAlias “Wi-Fi 2”
The output of this command will give us the DNS Server address on this Windows client machine. You can see from the output below that the DNS Server address on this client machine for the Wi-Fi network alias is 192.168.1.29.
At the same time, you can see that the command output also contains the DNS Server address for the IPv6 network as well.
Find DNS Server address using Get-NetIPconfiguration
An alternate approach to finding the DNS Server address on a Windows client machine is through the Get-NetIPConfiguration command. The command output of the cmdlet will show the network card and the associated DNS Server address for each network interface alias.
The following command will bring up the network interface cards on the client machine and share all the IP configuration data including the DNS Server address that has been setup on the client machine.
The output of this command looks like the screenshot below. You can see from the command output that the DNS Server address associated with the Wi-Fi network interface alias is 192.168.1.29. This is the same address that we found earlier using the Get-DNSClientserveraddress cmdlet.
The relevant part of the command output has been marked out. You can see that it lists the DNS Server address that is set up for the network alias ‘Wi-Fi 2’.
In this Powershell tutorial, we have seen that we can find the DNS Server address on a client machine using the Get-DNSClientServeraddress or Get-NetIPconfiguration cmdlets. To find the network interface alias we can use the Get-DNSclient cmdlet.
Suggested Powershell Tutorial
The following Powershell tutorials will help you in performing basic Windows system administration tasks. These commands have been tested and the screen shots have been placed for validation and verification.
- How to enable Remote Desktop using Powershell?
- Get CPU temperature using Powershell
- Get all hotfixes installed by date in Powershell
- How to find stopped services using Powershell?
- How to find running services in Powershell?
- How do I check if a directory exists in Powershell?
- How to get the first few lines of a file using Powershell?
- How to find the properties of an event log in Powershell?
- How to get event logs for an event using Powershell?
- How to export event logs to CSV file using Powershell?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
Rajesh Dhawan is a technology professional who loves to blog about smart wearables, Cloud computing and Microsoft technologies. He loves to break complex problems into manageable chunks of meaningful information.