Last active
August 29, 2015 14:24
-
-
Save abix-/74e007cc910d6ce86558 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cmdletbinding()] | |
Param ( | |
[Parameter(Mandatory=$true)]$domain | |
) | |
#Import Active Directory module | |
Import-Module ActiveDirectory | |
#Initialize arrays to store results | |
$results = @() | |
$zoneresults = @() | |
#Define output files | |
$outputFile = "$((Get-Location).Path)\Check-DNSZones_$($domain).csv" | |
$outputZoneFile = "$((Get-Location).Path)\Check-DNSZones_$($domain)_secondary.csv" | |
#Query Active Directory for a list of all domain controllers in $domain | |
$dcs = Get-ADDomainController -filter * -Server $domain | Select-Object -ExpandProperty HostName | Sort-Object | |
#For each domain controller.... | |
foreach($_d in $dcs) { | |
#Use WMI and query the domain controller for DNS information | |
$zones = gwmi -Class microsoftdns_zone -namespace root\microsoftdns -ComputerName $_d | |
#Filter collected data | |
$pri_zones = @($zones | ?{$_.ZoneType -eq 1}) | |
$sec_zones = @($zones | ?{$_.ZoneType -eq 2}) | |
Write-Host "$_d - Found $($pri_zones.count) primary zones and $($sec_zones.count) secondary zones" | |
#Store a list of Domain Controllers and the number of Primary and Secondary zones they have | |
$results += New-Object PSObject -Property @{ | |
DomainController = $_d | |
PrimaryZones = $pri_zones.count | |
SecondaryZones = $sec_zones.count | |
} | |
#For each Secondary Zone on the domain controller... | |
foreach($_s in $sec_zones) { | |
#Store detailed information about the Secondary Zone in another array | |
$zoneresults += New-Object PSObject -Property @{ | |
DomainController = $_d | |
SecondaryZone = $_s.Name | |
MasterServer0 = $_s.MasterServers[0] | |
MasterServer1 = $_s.MasterServers[1] | |
MasterServer2 = $_s.MasterServers[2] | |
MasterServer3 = $_s.MasterServers[3] | |
LastSuccessfulXfr = $_s.LastSuccessfulXfr | |
LastSuccessfulSoaCheck = $_s.LastSuccessfulSoaCheck | |
} | |
} | |
} | |
#Display the results to the console | |
$results | select DomainController, PrimaryZones, SecondaryZones | |
#Export the results to CSV | |
$results | select DomainController, PrimaryZones, SecondaryZones | Export-Csv $outputFile -NoTypeInformation | |
$zoneresults | select DomainController,SecondaryZone,MasterServer0,MasterServer1,MasterServer2,MasterServer3,LastSuccessfulXfr,LastSuccessfulSoaCheck | Export-Csv $outputZoneFile -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment