Powershell – DNS lookup

param (
[Parameter(Mandatory=$true)]
[string]$HostName
)
$output = $null
$output = @()
$DNSServers = Get-ADDomainController -Filter *
$DNSServers | foreach {
$query = Resolve-DnsName -Name $hostname -Server $_.HostName
$result = New-Object psobject -Property @{
dnsserver = $_.Name
hostname = $query.name
IPAddress = $query.ipaddress
}
$output += $result
}
$output | select hostname,ipaddress,dnsserver | sort ipaddress

save it as for example: dns-lookup.ps1 then

PS C:\Scripts> .\dns-lookup.ps1 server2016
hostname IPAddress dnsserver
-------- --------- ---------
server2016.domain.local 192.168.1.53 DC_01
server2016.domain.local 192.168.1.53 DC_02
server2016.domain.local 192.168.1.53 DC_09

Leave a Reply

Your email address will not be published. Required fields are marked *

20 − one =

This site uses Akismet to reduce spam. Learn how your comment data is processed.