
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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