Sometimes there is a need to fetch hostname records for multiple ip addresses. In my case I had a file with wrong hostnames. I had to quickly collect the proper hostnames to use them in another script.

$dir = "C:\Desktop\scripts\"
 
$report = @()
$ipaddress=Get-Content -Path $dir\iplist.txt
 
foreach ($ip in $ipaddress) {
    
    $response = [System.Net.Dns]::GetHostEntry("$ip")
    $HostName = $response.HostName
    $report += [pscustomobject]@{
        HostName = $HostName
        IpAddress = $ip
    }
}
$report