Following is a script that will enable you to query DNS for duplicate records. Be sure to change the location of the output file!
# Using WMI, retrieve all the duplicate DNS records
$DNS = Get-WmiObject -ComputerName 'DNS-Server' `
-Namespace 'root\MicrosoftDNS' `
-Class MicrosoftDNS_AType `
-Filter "ContainerName='Your Container'" | `
Group-Object OwnerName | Where-Object {$_.Count -gt 1}
# Create our CSV file to hold the data
$file = 'c:\temp\DNS.csv'
New-Item -ItemType file -Path $file -Force
Add-Content -Path $file -Value "Name,IPAddress"
# Iterate of the DNS items grabbing the name and IPAddress
foreach ($item in $DNS) {
foreach ($IPAddresses in $item.Group) {
$value = "{0},{1}" -f $item.name,$IPAddresses.IPAddress
Add-Content -Path $file -Value $value
}
}
Results should look something like:
Name | IPAddress |
Server1 | 10.194.111.22 |
Server2 | 10.140.111.22 |
ServerA | 10.333.19.121 |
ServerB | 10.333.131.24 |
Enjoy!
6 comments:
Awesome post! Got me thinking of the other things I can do with DNS and WMI. Thanks Wes!
Thanks Matt! Unfortunately, the script results (in our case) were not so pleasing… :)
So I ran this script on my dns server and it gives me duplicate names but no duplicate ip addresses.
Also is there a way to modify this so that it checks all zones?
Good readding this post
Post a Comment