Skip to main content

Resolve-DNSName Usage in Powershell

Resolve-DNSName Usage in Powershell

Resolve-DNSName is a new entry in Windows 8 and Server 2012 to replace our old friend Nslookup. Nslookup is still a great tool to query the DNS servers, but it has its limitations. For example, it is not easy to use inside the scripts. While these days, automation is very important part of every tool. Powershell introduces Resolve-DNSName that gives much more flexibility and options while querying the DNS Servers.

How Name Resolution Works:

The DNS resolution works in the following order:

  1. Hosts file is checked for any entry
  2. Local cached is checked for any cached records
  3. DNS Server is queried for name resolution

First it checks the hosts file for an entry for the queried domain, then it checks for the local cache, if the domain already queried or not and finally it quires the DNS Server, that is responsible for that domain.

Resolve-DNSName (Query As You Want):

Resolve-DNSName gives us the flexibility to query any of these options, that is not available in NSLookup. A normal Resolve-DNSName query looks like this:

For this example i have made an entry in the hosts file for with the IP


After adding the hosts file entry, now as soon i am querying the domain from my PC, it is returning the local IP.

Resolve-DNSName hosts

Here comes the fun part. We can mention to skip the hosts file by using “NoHostsFile” option to skip the hosts file check and move to the 2nd option. We can also mention“CacheOnly” to use cache or “DNSOnly” to directly query the DNS and skip Hosts and Cache.

Resolve-DNSName No Hosts

After using the NoHostsFile, it skips the host file and gets the actual IPs instead of the fake entry that i made in the hosts file.


Resolve-DNSName Record Types:

As a Systems Admin, i often require to get different types of DNS records, especially MX information for the domains. Now i can do that in Powershell using Type parameter in Resolve-DNSName command as follows:

Resolve-DNSName MX Record

Here i used the Resolve-DNSName command to fetch the MX record for my domain,

To list the DNS Servers that hold the record of any domain, we can use the “NS” (Short for Name Server). The output looks like this:

Resolve-DNSName Type NS

When we have multiple DNS Servers having record for any domain, we can query any specific DNS also for the record by specifying the Server. Here, i used Server IP from my previous output.

Resolve-DNSName Type NS Server

Similarly, we can query any type of records using Reolve-DNSName.

 Save Reults:

Finally, we can use the flexibility of Powershell to pipe the output to the Export-CSV and save the it in CSV format.

Resolve-DNSName Export


You can use “Get-Help Resolve-DNSName” to get detailed help for this command in Powershell or visit Technet documentation to learn more about it.