Learn Powershell | Achieve More


Home | Pages | Archives


Performing an Asynchronous DNS Lookup Using PowerShell

May 15, 2016 7:11 pm

This is another asynchronous approach to a common thing that a system administrator might do, much like a previous article I did on doing a speedy ping with PowerShell and async methods. I’ve already covered performance as well as handling each Task object so that won’t be covered here. Please review the linked blog for more information about those topics.

Instead of a ping, I am going to perform a lookup against DNS for an IP or hostname to get more information about a particular system or systems. The type that I am using to perform the DNS lookups is System.Net.Dns and the methods that I use are GetHostAddressesAsync() and GetHostEntryAsync().

Using both of these allows me to specify either an IPaddress or a hostname to perform the lookup against. Each item passed is tested to see if it is an IP address or not and then passed to the appropriate method that will be called with the data. Once that is done, it is passed to the Task watcher and then when everything has completed, you are presented with the results of each lookup.

The results of the command look something like this:

Get-DNSHostEntryAsync -Computername google.com,prox-hyperv,bing.com, github.com, `
powershellgallery.com, powershell.org,216.58.218.142

SNAGHTML87ff5b7

If you wanted to make this better, it is out on my GitHub repo so feel free to fork it and submit a PullRequest! Otherwise let me know what you think of it and enjoy!

Download Get-DNSHostEntryAsync

https://gallery.technet.microsoft.com/scriptcenter/Get-DNSHostEntryAsync-6fbd006c

Posted by Boe Prox

Categories: powershell

Tags: , ,

3 Responses to “Performing an Asynchronous DNS Lookup Using PowerShell”

  1. […] Source: Performing an Asynchronous DNS Lookup Using PowerShell | Learn Powershell | Achieve More […]

    By Performing an Asynchronous DNS Lookup Using PowerShell | Learn Powershell | Achieve More | Soyka's Blog on July 28, 2017 at 8:34 am

  2. I have submitted a pull request to GitHub with the proposed fix.

    By Robert Thomson on March 26, 2017 at 6:33 am

  3. I could be wrong but I think you used the wrong variable for the foreach which would affect the pipeline processing case.

    The line in the end block
    $Task = ForEach ($Computer in $Computername) {
    Should be
    $Task = ForEach ($Computer in $Computerlist) {

    By Robert Thomson on March 11, 2017 at 10:17 am

Leave a Reply



Mobile Site | Full Site


Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.