dns lookup script

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of NexGhost NexGhost 2 years, 6 months ago.

  • Author
    Posts
  • #15371
    Profile photo of NexGhost
    NexGhost
    Participant

    new to this board, saw on techED about this site. here is a small script i use to look up IP to DNS names:

    $Computerlist = get-content "./IPcomplist.txt"
    foreach ($i in $Computerlist){
    $rs = [System.Net.Dns]::GetHostbyAddress($i).HostName
    #FQDN driven
    #$rsIP = [System.Net.Dns]::GetHostAddresses($i)|select-object IPAddressToString -expandproperty  IPAddressToString
    $formatoutput = ($i + "," + $rs)
    write-output $formatoutput  |out-file Report_IP_FQDN.txt -append
    }
    $i=0
    write-output "script has finished running"
    

    -Nexghost

  • #15372
    Profile photo of Don Jones
    Don Jones
    Keymaster

    And as a note to folks working on Windows Server 2012, Windows 8, or later, there's a native cmdlet that will do this also. See http://technet.microsoft.com/en-us/library/jj590781.aspx for Resolve-DnsName.

  • #15421
    Profile photo of NexGhost
    NexGhost
    Participant

    been playing with the new "resolve-dnsname" cmdlet, actually pretty nice. maybe I can not have to use dig so much now......

You must be logged in to reply to this topic.