How to Get Machine Name Form Its Ip Address Using Powershell

nslookup command to get the list of machine names using powershell

Scenario:

I have list of machine IP, but I need name of the machines.

Solution:

To get he machine name I can use nslookup command, which returns the machine name using the DNS server.

So to get the list of machine names from the IP list I can use the below powershell script.


$machines = @{
    "machine1" = "10.20.100.12"
"machine2" = "30.40.102.56"
}

foreach($item in $machines.Values){
    $s = &nslookup $item
    Write-Host $s
}

Read-Host

Included Read-Host to wait util get key input from user

comments powered by Disqus
Previous

Related