PowerShell uses the power of .Net Framework thus you can leverage .Net classes in your PowerShell scripts.

In this example I’ll show you how you can perform DNS lookups using the Net.Dns class :

[System.Net.Dns]::GetHostentry(“blog.paux.fr”)

The result will be (depending if your input is a A or CNAME) :

HostName                  Aliases            AddressList
--------                  -------            -----------
dedibox2.jeanb-net.com    {}                 {88.191.92.204}

You can obviously pipe a list of hostname to this command and if you need to keep the original name you can add it to the resulted object and display it in a grid (new to PS2.0 !):

gc .\hosts.txt |% { [System.Net.Dns]::GetHostentry($_) | Add-Member -Name Host -MemberType NoteProperty -Value $_ -PassThru } | Select Host,AddressList | out-gridview

image

You can of course do the same with an IP address (or an IPv6 address):

[System.Net.Dns]::GetHostentry("2001:4860:a005::68")

The class in .Net Framework stay basic so you can’t resolve NS, SOA, MX or TXT records for example but you can try to use other classes as this implementation of a resolver in C# or using this one (that use the internal DNS resolver of Windows)

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Live
  • email
  • MySpace
  • Netvibes
  • Twitter
Tags Tags: , ,
Categories: English, Microsoft
Posted By: Jean-Benoit Paux
Last Edit: 04 Aug 2009 @ 12 17 AM

EmailPermalinkComments (0)
\/ More Options ...
Change Theme...
  • Users » 1
  • Posts/Pages » 18
  • Comments » 11
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Certifications



    No Child Pages.