Finding what Active Directory sites do not have domain controllers

Dear guys,
I hope you are all well.

We often have the issue whereby for whatever reason, we may go into AD sites and subnets, and find that a domain controller does not exist for a site.

What I woukd like to do is the following:
Build a query that:

1) Returns a list of all AD sites
2) For each site, query the presence of an NTDS settings object
3) Depending on the outcome of step 2), write the site name to one of 2 possible files:




So, for example, a site that has no NTDS settings object means it has no domain controller, so write its site name to the file: Site-dc-no.txt

Any help greatly appreciated.
Who is Participating?
JaihuntConnect With a Mentor Commented:
Command to find all DCs in the given site

>>dsquery server -o rdn -site <site name>

Command to find all DCs in the Forest

>>dsquery server -o rdn -forest

SubsunConnect With a Mentor Commented:
Try this PowerShell code.. it will export the required details to csv file..
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites | Select Name,@{N="DC's";E={$_.Servers -join ","}},@{N="DC Count";E={($_.Servers | Measure).Count}} | Export-Csv C:\report.csv -NTI

Open in new window

SandeshdubeyConnect With a Mentor Senior Server EngineerCommented:
You can also use dsquery server -forest to list the servername with site name.It will not list the empty site.
Simon336697Author Commented:
Thanks so much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.