$ips=Get-Content D:\IP_Address.txt               #fetch the ip from the text file located in D:\IP_Address.txt   foreach($ip in $ips){ $Hostname=[System.Net.Dns]::GetHostByAddress("$ip").HostName $ip+','+$Hostname | Out-File D:\hostdetails.txt -Append $Hostname=$Null $Ip=$Null } Powershell : Hostnames from IP | Powershell4You
top of page

Powershell to find server hostnames form IP address

To find host names of servers from a list of server ips using POWERSHELL

 

Situations may arise where we may need to find the server host names\FQDN from a set of ip addresses. This script helped me to get the required info easily at my finger tips.

 

Requirement : To get hostname of servers if the ip address are provided.

 

$ips=Get-Content D:\IP_Address.txt               #fetch the ip from the text file located in D:\IP_Address.txt  
foreach($ip in $ips){
$Hostname=[System.Net.Dns]::GetHostByAddress("$ip").HostName

$ip+','+$Hostname | Out-File D:\hostdetails.txt -Append

$Hostname=$Null

$Ip=$Null
}

bottom of page