Resolve IP address from Hostname (Updated May 2013)

Description: Return the IP address from a Hostname. Use the ipv6 or ipv4 only switches to return either. Beware using localhost will only return loopback addresses. Having to write 200 characters for the minimum description length for these is simply a waste of my time..

 
 
 
 
 
3.9 Star
(9)
7,953 times
Add to favorites
Networking
5/9/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How do you force the script to reference a text file with the list of host names in it?
    4 Posts | Last post May 09, 2013
    • How do you force the script to reference a text file with the list of host names in it?
    • I would recommend the following:
      $computers = Get-Content -Path C:\computers.txt
      Get-IPAddress -ComputerName $Computers
    • I tried to use the function by calling it as:
      
      Get-IPAddress "Server1" -IPV4Only
      
      The script generated an error at line New-Object PSOBJECT -Property <<<<  $Hash | Select ComputerName,IPAddress. The error stated that "Cannot validate argument on parameter 'Property'. The argument is null or empty."
      
      There seems to be a problem with the hash table statement although the script only outputs the ipv4 ip addresses. How can I just have the script output only the primary ip address of the machine like when I use the ping command in a command prompt windows like ping server1 -4?
      
    • Hey CluM09,
      
      I updated the code.
      
      Let me know how you go after you download it again.