
Ich versuche, eine Liste bestimmter DNS-Server zu durchsuchen (die ich in einer Datei habe) und dann nach einem bestimmten Hostnamen zu fragen. Das kann ich teilweise :)
Als nächstes möchte ich eine Liste der DNS-Server zurückgeben, die ein anderes Ergebnis als outlook-emea* zurückgeben. Ich möchte die IP des DNS-Servers und auch das Ergebnis.
Mein Problem ist, dass der DNS-Befehl CNAMES und A-Einträge zurückgibt. Ich bin nur an A-Einträgen interessiert und bin mir auch nicht sicher, wie ich die Ergebnisse filtern soll. Das ist, was ich bisher habe.
$Address = 'outlook.office365.com'
#$listofIPs = Get-Content 'C:\Users\user1\file.txt'
$listofIPs = '8.8.8.8'
$ResultList = @()
foreach ($ip in $listofIPs)
{
$Result = Resolve-DnsName -Name $Address -Type A -Server $ip
Write-Host ""
Write-Host DNS Server: -foregroundcolor "green" $ip
Write-Host ""
Write-Host Resolved Names: -foregroundcolor "green"
}
Kann jemand helfen?
Antwort1
Hier ist das Skript, das ich bisher habe, basierend auf Ihrem:
$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
}
Und hier ist das Ergebnis, das ich habe, wenn meine Textdatei 8.8.8.8, 8.8.8.4, 173.255.0.194 und 173.201.20.134 enthält: