Performing an Asynchronous DNS Lookup Using PowerShell

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,prox-hyperv,,, `,,


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

This entry was posted in powershell and tagged , , . Bookmark the permalink.

3 Responses to Performing an Asynchronous DNS Lookup Using PowerShell

  1. Pingback: Performing an Asynchronous DNS Lookup Using PowerShell | Learn Powershell | Achieve More | Soyka's Blog

  2. Robert Thomson says:

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

  3. Robert Thomson says:

    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) {

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s