How to Resolve DNS address using PowerShell?


To resolve the DNS address using PowerShell, we need to use the Resolve-DNS address command. This command works similarly to Nslookup command.

To resolve the A record (Name -> IP), you can directly provide the hostname and by default, it will retrieve all the records for the particular address.

Example

Resolve-DnsName -Name Test1-win2k12

Output

Name                            Type  TTL Section IPAddress
----                            ----  --- ------- ---------
Test1-Win2k12.labdomain.local    A   1200 Answer 192.168.0.107

-Name parameter doesn’t accept the multiple-input. Only the single input at one time. To enter multiple inputs, you need to use this command inside the loop. For example, We have a text file called severs.txt stored on the C:\Temp and we need to retrieve the A record from them.

Example

foreach($server in (Get-Content c:\temp\Servers.txt)){Resolve-DnsName -Name $server}

Output

foreach($server in (Get-Content c:\temp\Servers.txt)){Resolve-DnsName -Name
$server -Type A}

As mentioned earlier the default type is All, you can provide the specific type A in the above example to retrieve only A records.

To resolve the PTR record (IP -> Name), we need to provide the Type = PTR.

Example

Resolve-DnsName -Name 192.168.0.107 -Type PTR

Output

Name                         Type TTL   Section    NameHost
----                         ---- ---   -------    --------
107.0.168.192.in-addr.arpa. PTR  1200 Question TEST1-WIN2K12

Below are the types supported in the query.

UNKNOWN, A_AAAA, A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, MI NFO, MX, TXT, RP, AFSDB, X25, ISDN, RT, AAAA, SRV, DNAME, OPT, DS, RRSIG, NSEC, D NSKEY, DHCID, NSEC3, NSEC3PARAM, ANY, ALL, WINS

Updated on: 09-Nov-2020

14K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements