PowerShell Genie

Resolve-DnsName

Use Resolve-DnsName to query DNS for a name or address and return the records, bypassing the local cache when asked.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> Resolve-DnsName [-Name] <String> [[-Type] <recordtype>] [-Server <String[]>] [-DnsOnly] [-NoHostsFile] [-CacheOnly] [-DnssecOk] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

Resolve-DnsName [-Name] <String> [[-Type] <recordtype>] [-Server <String[]>] [-DnsOnly] [-NoHostsFile] [-CacheOnly] [-DnssecOk] [<CommonParameters>]
  1. Stage 1Resolve-DnsName-Name -Type -Server -DnsOnly -NoHostsFile -CacheOnly -DnssecOk

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    Resolve-DnsName -Name powershellgenie.com

    1PS> Resolve-DnsName -Name powershellgenie.com -Type A | Select-Object Name, IPAddress, TTL
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name                     Type  TTL  Section  IPAddress
    ----                     ----  ---  -------  ---------
    -Name                    A     300  Answer   10.20.30.11

    Resolve-DnsName -Name powershellgenie.com (2)

    1PS> Resolve-DnsName -Name powershellgenie.com -Server 1.1.1.1
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name                     Type  TTL  Section  IPAddress
    ----                     ----  ---  -------  ---------
    -Name                    A     300  Answer   10.20.30.11

    Resolve-DnsName -Name powershellgenie.com (3)

    1PS> Resolve-DnsName -Name powershellgenie.com -Type MX -NoHostsFile
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Name                     Type  TTL  Section  IPAddress
    ----                     ----  ---  -------  ---------
    -Name                    A     300  Answer   10.20.30.11

    Parameters

    Parameter definitions:

    • -Name
    • -Type
    • -Server
    • -DnsOnly
    • -NoHostsFile
    • -CacheOnly
    • -DnssecOk

    PowerShell module reference on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use Resolve-DnsName when you need to query DNS for a name or address and return the records, bypassing the local cache when asked. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: NXDOMAIN means the queried name was not found by the DNS path used. Check the exact name, suffix and selected server, then distinguish missing records from transport timeouts. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Test-NetConnection. Resolve-DnsName tests DNS resolution; Test-NetConnection can test a TCP port. A correctly resolved hostname does not prove that the application is reachable. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    Resolve-DnsName reference on Microsoft Learn

    Recap

    Resolve-DnsName Use Resolve-DnsName to query DNS for a name or address and return the records, bypassing the local cache when asked.

    Next: Resolve-Path
    Genie guideResolve-DnsName

    Use Resolve-DnsName to query DNS for a name or address and return the records, bypassing the local cache when asked. The console below is pre-loaded — run it, then change a value and run it again.