See if this works for you:
Get-Content ".\ip4.txt" |
ForEach-Object{
$result = [ordered]@{
DNSName = $_.Trim()
HostName = ""
DNSIPv4 = ""
Up = ""
TestedIPv4 = ""
}
Try{
$entry = [System.Net.Dns]::GetHostEntry($_.Trim())
$result.HostName = $entry.HostName
$entry.AddressList |
Where-Object {$_.AddressFamily -eq 'InterNetwork'} |
ForEach-Object{
$result.DNSIPv4 = $_.IPAddressToString
[array]$x = Test-Connection -Delay 15 -ComputerName $result.DNSName -Count 1 -ErrorAction SilentlyContinue
if ($x){
$result.Up = "Yes"
$result.TestedIPv4 = $x[0].IPV4Address
}
else{
$result.Up = "No"
$result.TestedIPv4 = "N/A"
}
}
}
Catch{
$result.HostName = "Host Unknown"
$result.Up = "Unknown"
$result.TestedIPv4 = "N/A"
}
[PSCustomObject]$result
}
You can pipe the results to Export-Csv or Format-Table. There's no red or green, but you can get what you need from a CSV and select or sort as you like.