PowerShell DNS Lookup: Resolve-DnsName and nslookup

PowerShell DNS Lookup: Resolve-DnsName and nslookup

PowerShell Tips Editor 4 min read
PowerShell DNS Lookup: Resolve-DnsName and nslookup

Email delivery failing? DNS misconfiguration is usually the culprit — and a PowerShell DNS lookup via Resolve-DnsName is the fastest way to dig from the command line without reaching for a separate tool. Whether you need to check an A record, verify SPF and DMARC TXT records, trace a CNAME chain, or confirm that a new DNS change has propagated, Resolve-DnsName returns structured objects you can filter, export, and compare programmatically.

Basic Forward Lookup

A forward lookup translates a hostname to an IP address. Resolve-DnsName is available on Windows 8 / Server 2012 and later. It queries your system’s default DNS server unless you specify another.

Resolve-DnsName -Name "powershelltips.com"
Name                                           Type   TTL   Section    IPAddress
----                                           ----   ---   -------    ---------
powershelltips.com                             A      3600  Answer     93.184.216.34

To get just the IP address from the result:

(Resolve-DnsName -Name "powershelltips.com" -Type A).IPAddress

Reverse Lookup (PTR Record)

A reverse lookup maps an IP address back to a hostname using PTR records. Pass the IP as the name — PowerShell automatically converts it to the correct in-addr.arpa format.

Resolve-DnsName -Name "8.8.8.8" -Type PTR
Name                        Type  TTL    Section  NameHost
----                        ----  ---    -------  --------
8.8.8.8.in-addr.arpa        PTR   21599  Answer   dns.google

Query Specific Record Types (MX, CNAME, TXT)

Use the -Type parameter to request specific DNS record types. This is essential for mail flow troubleshooting (MX), redirect chains (CNAME), and SPF/DMARC verification (TXT).

# MX records — mail server priority
Resolve-DnsName -Name "example.com" -Type MX | Sort-Object Preference

# CNAME resolution
Resolve-DnsName -Name "www.example.com" -Type CNAME

# TXT records — SPF, DMARC, verification tokens
Resolve-DnsName -Name "example.com" -Type TXT | Select-Object -ExpandProperty Strings

Note that the -Type parameter uses the same record type names as DNS standards: A, AAAA, MX, CNAME, TXT, NS, SOA, PTR, SRV.

Use a Specific DNS Server

By default Resolve-DnsName uses your system resolver. To query a specific DNS server — such as Google’s 8.8.8.8 or your internal DNS — add the -Server parameter. This is critical for diagnosing propagation: query your old provider and your new one to compare responses.

# Query Google's public DNS
Resolve-DnsName -Name "example.com" -Server "8.8.8.8" -Type A

# Query your internal DNS server
Resolve-DnsName -Name "intranet.corp.local" -Server "10.0.0.1" -Type A

Bulk Lookup from CSV

When you need to audit a list of domains — checking whether each resolves or finding which ones have MX records — load a CSV and loop through each name. This approach scales to hundreds of domains with a single script.

$domains = Import-Csv -Path "C:\Logs\domains.csv" # Column header: Domain

$results = foreach ($row in $domains) {
    try {
        $record = Resolve-DnsName -Name $row.Domain -Type A -ErrorAction Stop
        [PSCustomObject]@{
            Domain  = $row.Domain
            IP      = ($record | Where-Object Type -eq "A").IPAddress -join ", "
            Status  = "Resolved"
        }
    } catch {
        [PSCustomObject]@{
            Domain  = $row.Domain
            IP      = ""
            Status  = "Failed"
        }
    }
}

$results | Export-Csv -Path "C:\Logs\dns-report.csv" -NoTypeInformation

Diagnose DNS Propagation

After a DNS change, compare the result from multiple public resolvers to check whether propagation has reached each one. A quick loop across well-known public DNS servers shows you the current state at a glance.

$dnsServers = @{
    "Google"      = "8.8.8.8"
    "Cloudflare"  = "1.1.1.1"
    "OpenDNS"     = "208.67.222.222"
}

foreach ($provider in $dnsServers.GetEnumerator()) {
    $ip = (Resolve-DnsName -Name "example.com" -Server $provider.Value -Type A -ErrorAction SilentlyContinue).IPAddress
    Write-Output "$($provider.Key): $ip"
}
Google: 93.184.216.34
Cloudflare: 93.184.216.34
OpenDNS: 203.0.113.1

Common Errors and Fixes

  • Resolve-DnsName not available on older Windows versions: Resolve-DnsName requires Windows 8 / Server 2012 or later. On older systems, fall back to [System.Net.Dns]::GetHostAddresses("hostname") for basic A record lookups. For Windows 7 / Server 2008, the nslookup executable is still available as a last resort.
  • Record type parameter names differ from dig/nslookup conventions: nslookup accepts query types like mx or txt in lowercase as plain strings. With Resolve-DnsName, use the -Type parameter with the uppercase record type. Also note that ANY queries are not always supported by all resolvers and may return empty results.

Related Cmdlets / See Also

Wrapping Up

Resolve-DnsName is your Swiss Army knife for DNS diagnostics from the PowerShell prompt — forward lookups, reverse lookups, MX checks, and propagation testing all in one consistent interface. As a next step, build a scheduled script that monitors critical DNS records nightly and alerts you if they change unexpectedly.

Send-Item -To