Aqui está o script que eu tenho até agora, baseado no seu:
$Address = "outlook.office365.com"
$listofIPs = Get-Content "C:\file.txt"
$ResultList = @()
foreach ($ip in $listofIPs)
{
# The following query will list only records begining with "outlook-", but not begining with "outlook-emea"
$DNSquery = (Resolve-DnsName -Name $Address -Type A -Server $ip).Name | Where-Object {$_ -inotlike "outlook-emea*" -and $_ -ilike "outlook-*"}
# We assume, based on several tests, that selecting the first result for the previous query is enough.
$Result = $DNSquery | Select -First 1
if ($DNSquery)
{
# Creating custom object to feed the array
$Object = New-Object PSObject
$Object | Add-Member -MemberType NoteProperty -Name "DNS Server IP" -Value $ip
$Object | Add-Member -MemberType NoteProperty -Name "Result" -Value $Result
$ResultList += $Object
}
# Displaying the array with the results
$ResultList
}
E aqui está o resultado que tenho, quando meu arquivo de texto contém 8.8.8.8, 8.8.8.4, 173.255.0.194 e 173.201.20.134: