Resolve Hostname


posted by Tobias Weltner
11-10-2008

Downloads: 402
File size: 135 B
Views: 3,342

Embed
Resolve Hostname
  1. $result = [System.Net.Dns]::GetHostByName('microsoft.com'
  2.  
  3. $result 
  4. $result.AddressList | ForEach-Object { $_.IPAddressToString  
Filed under: , , ,
Resolves a host name using .NET and returns all IP-Addresses

Comments

MBermejo wrote re: Resolve Hostname
on 11-12-2008 12:40 PM

How can you make it so that you use Read-host to make the script usable by giving it the host name to resolve instead of hard coding?

Aleksandar wrote re: Resolve Hostname
on 11-12-2008 6:24 PM

PS[1]>$hostname = read-host "Enter a host name"

Enter a host name: microsoft.com

PS[2]>$result = [System.Net.Dns]::GetHostByName("$hostname")

PS[3]>$result.AddressList | ForEach-Object { $_.IPAddressToString  }

MBermejo wrote re: Resolve Hostname
on 11-15-2008 2:27 PM

Thanks.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.