- Windows resolve dns name
- Adam the Automator
- Resolve-DnsName: Resolving DNS Records with PowerShell
- June Castillote
- Prerequisites
- Resolve-DnsName: The PowerShell DNS Resolver
- Querying Different Types of DNS Records
- Using Specific Servers for DNS Lookup
- Reporting DNS Records using PowerShell Script
- Defining the Variables
- Performing DNS Lookups
- Conclusion
- Resolve-Dns Name
- Syntax
- Description
- Examples
- EXAMPLE 1
- EXAMPLE 2
- EXAMPLE 3
- EXAMPLE 4
- Parameters
- Inputs
- Outputs
Windows resolve dns name
- Open up the command prompt (In Windows, you can use WINDOWS KEY+R to open Run dialogue box and type cmd)
(note: Use your up and down arrow keys to access recent commands you have entered in the command line.)
To see your current DNS settings, type ipconfig /displaydns and press Enter.
To delete the entries, type ipconfig /flushdns and press Enter.
To see your DNS settings again, type ipconfig /displaydns and press Enter.
You should see blank records or you might get the message «Could not display the DNS Resolver Cache.»
To perform a DNS lookup, type ping scisweb.ulster.ac.uk and press Enter.
To see your DNS settings again, type ipconfig /displaydns and press Enter.
You should see a DNS record for scisweb.ulster.ac.uk that includes the IP address and other information. Another field in the DNS cache is a TTL value, which is different from the TTL in an IP packet. This DNS TTL value is sent by the DNS server maintaining the scisweb.ulster.ac.uk record. It is measured in seconds and tells your DNS client how long to cache the DNS record as a safeguard against clients holding on to DNS records whose IP addresses might have changed.
To open your computer’s Hosts file, run Notepad as administrator. Easiest way is to press and then type notepad in windows 8 splashscreen, select notepad and right click and then select «Run as administrator» in bottom taskbar area of windows 8. In the Open dialog box, navigate to C:\Windows\System32\Drivers\Etc. In the File type drop-down list, click All Files. Double-click the hosts file to open it.
You should now have a hosts file open with various settings.
After the last line in the file, type 193.61.191.104 university, and then save the file and exit Notepad.
At the command prompt, type ipconfig /displaydns and press Enter to see that the entry is in your DNS cache.
Type ping university and press Enter.
Delete the DNS cache again by typing ipconfig /flushdns and press Enter.
Display your DNS cache by typing ipconfig /displaydns and press Enter.
Notice that the university entry remains in the cache because the Hosts file data always stays in the cache.
Type nslookup scisweb.ulster.ac.uk and press Enter.
Your DNS server’s name and IP address are displayed, along with the name and IP address of www.ulster.ac.uk. You use Nslookup to look up a host’s IP address without actually communicating with it.
Type nslookup and press Enter.
You should now have entered Nslookup’s interactive mode. You should see an arrow prompt.
Type www.google.com and press Enter.
Notice that more than one address is returned along with one or more aliases (other names that www.google.com goes by).
Type www.google.com again (or press the up arrow to repeat the last line you typed) and press Enter.
You should see the IP addresses returned in a different order. (If you don’t, keep trying, and the order will change.)
The www.google.com page can be reached by a number of different IP addresses, and the addresses are returned in a different order so that a different server is used each time, which is called load balancing.
Nslookup is also used to do reverse lookups, in which the IP address is given and the hostname is returned.
If you are ever concerned that your DNS server is not working correctly, you can test it with Nslookup and compare the results of your DNS server with the results from another server, such as Google’s.
Adam the Automator
Resolve-DnsName: Resolving DNS Records with PowerShell
June Castillote
Read more posts by this author.
If you’re managing web or mail servers, you know how heavily these servers rely on adequately configured DNS records. Missing DNS records can cause all sorts of problems, including users not being able to find your website or non-delivery of emails. It is a good thing that the PowerShell Resolve-DnsName cmdlet exists, and with it, monitoring DNS records can be automated through scripting.
An admin’s day is already full enough, and manually checking whether DNS records can be appropriately resolved means more manual effort.
In this article, you will learn what and how to use the Resolve-DnsName cmdlet to query DNS records with PowerShell. By the end of this article, you will have also learned how to create a basic script to make a report of your nominated DNS records to monitor.
Table of Contents
Prerequisites
This article is a walk-through, and if you plan to follow along with the examples, you will need:
Resolve-DnsName: The PowerShell DNS Resolver
There is more than one way to perform a DNS query. The Resolve-DnsName cmdlet is similar to the nslookup command-line tool that comes with Windows, or the dig command if you’re more of a Linux admin.
Some websites offer DNS record monitoring/reporting services. But, these third party services mostly come with a cost, of course. There’s a free alternative, which also allows you to show off your scripting skills!
The Resolve-DnsName cmdlet, as its name implies, resolves DNS names to IP addresses and vice versa. This cmdlet is part of the dnsclient PowerShell module that, as of this writing, shipping with Windows 10, Windows Server 2012/R2, Windows Server 2016, and Windows Server 2019.
Because Resolve-DnsName is a PowerShell cmdlet, it returns its results as objects that can be stored, manipulated, and exported. For example, looking up the DNS record of google.com using the command Resolve-DnsName google.com give you the output shown below.
The result was returned as an object that allows you to export the results to a CSV file, or manipulate the format to produce HTML reports.
The Resolve-DnsName cmdlet is different than the old school nslookup utility. nslookup returns a simple string. You can see an example in the following screenshot. If you need to parse out any of this information, it’s going to be a struggle.
Querying Different Types of DNS Records
By default, Resolve-DnsName queries the A and AAAA types of DNS records. For example, if you look up the DNS record for gmail.com using the command below:
As you can see below, only the AAAA and A records are returned. That’s because the DNS record type to look up was not specified.
Now, given that we all know that gmail.com is an email domain used by Google’s email service, there must be an MX record associated with it, right? Well, there’s no need to assume when you can confirm by using this command:
The output shown in the screenshot below shows the MX record list for gmail.com.
To know more about the different record types that can be used with Resolve-DnsName , visit this link and look for the table for the -Type parameter. Or you can just refer to the Resolve-DnsName help using the command get-help Resolve-DnsName .
Using Specific Servers for DNS Lookup
Resolve-DnsName uses the DNS server addresses configured on your computer by default. But, you can also make Resolve-DnsName use a specific DNS server when performing lookups.
For example, if you want to use Google Public DNS to lookup records, you can do so by adding the -Server parameter in your command similar to the example below.
The result of the command above would be similar to the one shown in the screenshot below.
At this point, you might be asking, “why would I need to use a different DNS server?”. That is a valid question. If you try looking up the same record using the default DNS server of your machine, or another DNS server, you might probably get the same result.
There could be many reasons to use different DNS servers with Resolve-DnsName . Some of these reasons may include:
- Speed – Some DNS servers may perform faster than others.
- Security – Some DNS servers may have more security measures than others that prevent hijacks and attacks.
- Records availability – In most scenarios, organizations have their own internal DNS servers that contain the zones and records for names that are only resolved internally. In this case, looking up an internal name using a public DNS server will fail.
- DNS servers are not forwarding requests – Some organizations do not allow DNS forwarding. Using them for DNS lookup of public DNS records will fail.
- Troubleshooting and Testing – When your favorite DNS servers are acting up, you may want to test your lookups using a different DNS server.
Reporting DNS Records using PowerShell Script
Now that you’ve learned the basics of how to use the Resolve-DnsName cmdlet, in this section, you’ll learn to create a PowerShell script to monitor and report DNS records. You should be able to apply the knowledge you’ve gained in the previous sections so far in building this script.
Fire up your script editor of choice and create a new file named GetDnsRecord.ps1.
Defining the Variables
First, determine variables to use. These variables will include the following:
- $NameList – This variable will hold the names of the DNS records you want your script to query
- $Serverlist – Use this variable to indicate the DNS servers that will be used by the script for lookups.
Copy the code below and paste it at the beginning of your script.
Performing DNS Lookups
Next, the code must be able to look up the DNS record of each of the names specified. In this case, the foreach loop will be used to iterate the list of records and look up each name using Resolve-DnsName .
The line $FinalResult = @() creates an empty array where the final result will be stored. Then, using the foreach loop, PowerShell passes each item in the $NameList variable to a variable named $Name .
In every iteration, the line $tempObj = «» | Select-Object Name,IPAddress,Status,ErrorMessage creates a temporary object with four properties is created to hold the result of succeeding DNS lookup.
Next, the try<> statement is used to run the Resolve-DnsName command to lookup DNS A records and populate the $tempObj values. If in case the DNS lookup fails, the catch<> statement catches the error, and the error will be included in the $tempObj object.
At the end of each iteration, the value of the $tempObj object will be appended to the $FinalResult . And once the last item in the $NameList array is processed, the loop will exit. Then, the value of the $FinalResult will be displayed.
Copy the code below and paste it at the end of your script. There is no need to change any values.
After saving the script, run it in PowerShell by calling its name GetDnsRecord.ps1. The demonstration below shows the output.
As you can see from the result above, the output is an object which is useful if you want to export the results to file like CSV using the command below.
The CSV output would look similar to the one below.
Conclusion
In this article, you’ve learned the basics of how to use the Resolve-DnsName cmdlet to perform DSN records lookup in PowerShell. You’ve also learned how Resolve-DnsName is different from other tools like the nslookup utility.
You’ve seen how Resolve-DnsName can be used in a script to automate the DNS record lookup. This would be useful as a monitoring tool to ensure that you are aware of the current status of the DNS records that you look after.
Using your PowerShell scripting skills, the reporting script can be further enhanced by adding code to automatically send the report by email to specified recipients. It can also be modified to create a visually pleasing HTML output.
In the end, Resolve-DnsName is an excellent tool for DNS lookup whether you use it manually or for automation in scripts. Now you have the knowledge about how it works, and it is up to you to find ways to use it as part of your administration tasks.
Resolve-Dns Name
Performs a DNS name query resolution for the specified name.
Syntax
Description
The Resolve-DnsName cmdlet performs a DNS query for the specified name. This cmdlet is functionally similar to the nslookup tool which allows users to query for names.
Examples
EXAMPLE 1
This example resolves a name using the default options.
EXAMPLE 2
This example resolves a name against the DNS server at 10.0.0.1.
EXAMPLE 3
This example queries for A type records for name www.bing.com.
EXAMPLE 4
This example resolves a name using only DNS. LLMNR and NetBIOS queries are not issued.
Parameters
Resolves this query using only the local cache.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Resolves this query using only the DNS protocol.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Sets the DNSSEC checking-disabled bit for this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Sets the DNSSEC OK bit for this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Allows falling back to the LLMNR protocol when resolving this query with DNS fails.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Resolves this query using only the LLMNR or NetBIOS protocols.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Resolves this query using only the LLMNR protocol.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the name to be resolved.
Type: | String |
Position: | 0 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Allows fallback to the NetBIOS protocol when resolving this query with DNS fails.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Skips the hosts file when resolving this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies not to use IDN encoding logic for the query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Instructs the server not to use recursion when resolving this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Uses shorter timeouts for this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the IP addresses or host names of the DNS servers to be queried. By default the interface DNS servers are queried if this parameter is not supplied.
Type: | String [ ] |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Uses only TCP for this query.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Specifies the DNS query type that is to be issued. By default the type is A_AAAA, the A and AAAA types will both be queried. The acceptable values for this parameter are:
— A_AAAA = 0, the DNS query type is A_AAAA.
— A = 1, the DNS query type is IPv4 server Address.
— AAAA = 28, the DNS query type is IPv6 server address.
— NS = 2, the DNS query type is name server.
— MX = 15, the DNS query type is mail routing information.
— MD = 3, the DNS query type is mail destination.
— MF = 4, the DNS query type is mail forwarder.
— CNAME = 5, the DNS query type is canonical name.
— SOA = 6, the DNS query type is start of authority zone.
— MB = 7, the DNS query type is mailbox domain name.
— MG = 8, the DNS query type is mail group member.
— MR = 9, the DNS query type is mail rename name.
— NULL = 10, the DNS query type is null resource record.
— WKS = 11, the DNS query type is well known service.
— PTR = 12, the DNS query type is domain name pointer.
— HINFO = 13, the DNS query type is host information.
— MINFO = 14, the DNS query type is mailbox information.
— TXT = 16, the DNS query type is text strings.
— RP = 17, the DNS query type is responsible person.
— AFSDB = 18, the DNS query type is AFS database servers.
— X25 = 19, the DNS query type is packet switched wide area network.
— ISDN = 20, the DNS query type is Integrated Services Digital Network.
— RT = 21, the DNS query type is DNS route through.
— SRV = 33, the DNS query type is server selection.
— DNAME = 39, the DNS query type is domain aliases.
— OPT = 41, the DNS query type is DNS option.
— DS = 43, the DNS query type is delegation signer.
— RRSIG = 46, the DNS query type is DNSSEC signature.
— NSEC = 47, the DNS query type is next-secure record.
— DNSKEY = 48, the DNS query type is DNS key record.
— DHCID = 49, the DNS query type is Dynamic Host Configuration Protocol information.
— NSEC3 = 50, the DNS query type is NSEC record version 3.
— NSEC3PARAM = 51, the DNS query type is NSEC3 parameters.
— ANY = 255, the DNS query type is wildcard match.
— ALL = 255, the DNS query type is wildcard match.
Type: | RecordType |
Accepted values: | UNKNOWN, A_AAAA, A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, MINFO, MX, TXT, RP, AFSDB, X25, ISDN, RT, AAAA, SRV, DNAME, OPT, DS, RRSIG, NSEC, DNSKEY, DHCID, NSEC3, NSEC3PARAM, ANY, ALL, WINS |
Position: | 1 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
None
Outputs
Microsoft.DnsClient.Commands.DnsRecord
The DnsRecord object contains all of the records returned from the wire for the specified DNS query.