DevOps

Resolve-DNSname: PowerShell DNS Lookup

Learn PowerShell's Resolve-DnsName cmdlet. Discover its usage, versatility, and the added value it brings to DNS queries and troubleshooting.

Let’s look at a very cool and powerful DNS troubleshooting tool that is included as a PowerShell cmdlet. The Resolve-DnsName PowerShell cmdlet is a tool that includes the features of many of the legacy command line tools. Let’s see how to use it.

Understanding DNS

DNS has been called by many the “phone book” of the Internet. It allows us to resolve or translate IP addresses that aren’t very easy to remember, into domain names that are much easier to remember. So, it is a very important layer in modern computer networking.

DNS is the Internets phonebook
DNS is the Internets phonebook

Resolve-DnsName

PowerShell has a cmdlet called Resolve-DnsName. It can do DNS lookups and return a lot of information about the name of the resource. It can look up different DNS record types and is a tool that is good to remember when troubleshooting connectivity issues or any other problem where DNS could be in play.

PowerShell is built into Windows and is readily available with handy cmdlets for troubleshooting.

PowerShell is built in and has many great network cmdlets
PowerShell is built in and has many great network cmdlets

Below, we are running the Resolve-DNSName cmdlet.

Running the Resolve-DNSName cmdlet
Running the Resolve-DNSName cmdlet

Resolve-DnsName can replace other tools

Here are a few of those traditional tools that PowerShell’s Resolve-DnsName can replace if you want to use it instead of other tools.

NSLookup

NSLookup is a command-line tool for querying the DNS system to obtain domain names or IP address mapping or other DNS records. It’s been a default component of Windows for many years. However, Resolve-DnsName provides a more PowerShell-friendly DNS query experience with enhanced functionality and more flexible output.

Dig

Dig (Domain Information Groper) is a Linux utility for querying DNS servers. It is known for being a great tool for investigating DNS records. However, it’s not installed by default on many systems, and its use involves a syntax that can be challenging for some users. Resolve-DnsName is a tool for Windows users that can perform the same types of queries without installing additional software or having access to a Linux box.

Resolve-DnsName Parameters

Resolve-DnsName cmdlet provides many different parameters that allow the customization of DNS queries. For instance, you can tell the cmdlet you want the DNS query type to be a certain type and the DNS record you want, such as A, AAAA, CNAME, MX, NS, PTR, SOA, SRV, or TXT.

Use Case: Mail Routing Information

A common use case for Resolve-DnsName is checking mail routing information. You can determine a domain’s mail forwarder by querying MX records. This information is critical for troubleshooting mail delivery issues or configuring mail servers.

The Impact of Hosts File on DNS Resolution

The hosts file can affect the outcome of DNS queries. Before the Resolve-DnsName cmdlet hits the DNS server, it checks the local hosts file for entries. This can provide a means to test DNS changes without modifying actual DNS records.

Also, if you are looking to bypass the hosts file, Resolve-DNSName has a parameter that allows easily using only DNS resolution to help determine if a stale hostname is in play. We will show an example of that below.

Resolve-DnsName examples

Below are a few examples of using the Resolve-DNSName cmdlet to investigate DNS records.

Example 1: Simple DNS Query

The most basic use of Resolve-DnsName is to perform a simple DNS query. The syntax is straightforward:

Resolve-DnsName -Name "www.example.com"
Resolve DNSname basic usage
Resolve DNSname basic usage

This command will return different DNS records associated with “www.example.com“. By default, this includes A (IPv4) and AAAA (IPv6) records which provide the IP address(es) for the queried domain.

Example 2: Specifying DNS Query Type

The Resolve-DnsName cmdlet can take parameters where you tell it what kind of DNS record you wish to query using the -Type parameter. For example, if you want to retrieve MX (Mail Exchange) records, use the following command:

Resolve-DnsName -Name "example.com" -Type MX

This command will return MX records, providing mail routing and mail destination information for “example.com“.

Querying MX records with Get DNSname PowerShell cmdlet
Querying MX records with Get DNSname PowerShell cmdlet

Example 3: Querying a Specific DNS Server

Sometimes you may need to perform DNS lookups against a specific DNS server. You can do this using the -Server parameter:

Resolve-DnsName -Name "www.example.com" -Server "8.8.8.8"

This command will run the cmdlet and perform the DNS lookup for “www.example.com” using Google’s public DNS server (IP address 8.8.8.8) and look up the server address.

Example 4: Resolving CNAME Records

CNAME records map a domain (alias) to another (canonical name) domain. To retrieve CNAME records, use the -Type parameter with “CNAME”:

Resolve-DnsName -Name "www.example.com" -Type CNAME
Querying CNAME records with Get DNSname
Querying CNAME records with Get DNSname

This will display the canonical name for “www.example.com“, if a CNAME record exists.

Example 5: Finding Authority Zone

You can get the Name Server (NS) records, which indicate the authority zone for a specific domain:

Resolve-DnsName -Name "example.com" -Type NS
Getting NS records using PowerShell
Getting NS records using PowerShell

This command will list the authoritative DNS servers (name servers) for the domain “example.com“.

Example 6: Getting TXT Records

TXT records hold various types of textual information and can be used, for example, for domain verification or to retrieve SPF records. Here’s how to retrieve them:

Resolve-DnsName -Name "example.com" -Type TXT
Querying for TXT records using Get DNSname
Querying for TXT records using Get DNSname

This command returns the TXT records for “example.com“.

Replacing “example.com” with your target domain is always good practice. These examples are a mere glimpse into the capabilities of Resolve-DnsName. By exploring the other parameters and types, you can perform comprehensive DNS investigations and troubleshoot with this cmdlet.

Example 7: Resolving PTR Records

Pointer (PTR) records, also known as Reverse DNS records, map an IP address to a hostname. This can be useful for reverse lookups, where you have an IP address and want to find the associated hostname.

Resolve-DnsName -Name "8.8.8.8" -Type PTR
View PTR records for a domain
View PTR records for a domain

This command performs a reverse lookup on Google’s public DNS server IP address.

Example 8: Utilizing the Pipeline

PowerShell is famous for its pipeline input feature, which allows you to pass the output of one command as input to another. Here is an example of using Resolve-DnsName with a pipeline:

"www.example.com", "www.google.com" | Resolve-DnsName
Using piping with Get DNSname
Using piping with Get DNSname

In this command, DNS resolution is performed for both “www.example.com” and “www.google.com“. The pipe operator (|) passes each domain name to the Resolve-DnsName cmdlet.

Example 9: Obtaining Fully Qualified Domain Names (FQDNs)

The -DnsOnly switch is used to get only the DNS protocol result of a query without the potential influences of NetBIOS or local hosts files. For instance:

Resolve-DnsName -Name "example" -DnsOnly
You can bypass the hosts file and query DNS only
You can bypass the hosts file and query DNS only

The result will be the Fully Qualified Domain Name (FQDN) of the “example” that is obtained purely from the DNS resolution.

Awesome DNS Server for home

Speaking of DNS, check out my video on how to easily install and configure Unbound DNS for your home lab:

Best DNS server for home lab

Wrapping Up

While looking at Resolve-DnsName more closely, we’ve highlighted how it allows for detailed DNS queries that surpass the capabilities of traditional tools like NSLookup, Dig, and the Host command. With it, admins can quickly investigate DNS queries, extract DNS records, and troubleshoot DNS issues.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

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.