Extract DNS details of multiple servers

I recently helped someone setup DNS scavenging. We wanted to know what we are getting into and needed to confirm that all Servers are configured with static IPs in DNS. We found just that using below script. It not only exports all DNS details of servers but also logs the one which are missing in DNS.

Get-ADComputer -SearchBase "OU=servers,DC=domain,DC=net" -Filter * -Properties * | select name,description,canonicalname,whencreated,@{Name="Last Logon Timestamp";Expression={([datetime]::FromFileTime($_.LastLogonTimeStamp))}} | Export-Csv "c:\temp\ServerDetails.csv" -NoTypeInformation
$servers= (Import-Csv "C:\temp\ServerDetails.csv").name
foreach ($server in $servers)
Try {
    Get-DnsServerResourceRecord -ZoneName domain.net -ComputerName DNS-Server-Name.domain.net -Name $server -ErrorAction stop | select hostname,RecordClass,RecordType,Timestamp,TimeToLive,Type | Export-Csv "c:\temp\DNS Details of Servers.csv" -Append -NoTypeInformation
Catch [Microsoft.Management.Infrastructure.CimException]{
    Write-Output $server | out-file "c:\temp\Server records missing in DNS.txt" -Append    


Leave a Reply

Your email address will not be published.