Published on

How to List All Domain Controllers in Active Directory (PowerShell Script)

Before troubleshooting replication, authentication, or planning a DC decommission, you need the basic inventory: which DCs exist, which site each one belongs to, which are global catalogs, and which FSMO roles are where. It's not a lot of information, but it's scattered across a few different cmdlets if you go looking for it piecemeal.

The quick answer

Get-ADDomainController -Filter * |
    Select-Object HostName, IPv4Address, Site, IsGlobalCatalog, IsReadOnly, OperationMasterRoles

A more useful reporting script

#requires -Modules ActiveDirectory
<#
.SYNOPSIS
    Reports every domain controller in the domain, with site, roles, and
    global catalog status.
#>

[CmdletBinding()]
param(
    [string]$OutputCsv
)

Import-Module ActiveDirectory -ErrorAction Stop

$domainControllers = Get-ADDomainController -Filter *

$results = $domainControllers |
    Select-Object HostName,
                  IPv4Address,
                  Site,
                  IsGlobalCatalog,
                  IsReadOnly,
                  OperatingSystem,
                  @{Name = 'FsmoRoles'; Expression = { if ($_.OperationMasterRoles) { $_.OperationMasterRoles -join ', ' } else { '(none)' } } } |
    Sort-Object HostName

Write-Host "Found $(@($results).Count) domain controller(s)." -ForegroundColor Cyan
$results | Format-Table HostName, Site, IsGlobalCatalog, IsReadOnly, FsmoRoles -AutoSize

if ($OutputCsv) {
    $results | Export-Csv -Path $OutputCsv -NoTypeInformation
    Write-Host "Exported results to $OutputCsv" -ForegroundColor Green
}

No -SearchBase here — domain controllers are always domain-wide by nature, so unlike most of the other scripts in this repo, there's nothing to scope down.

Reading the FSMO roles column

A DC with (none) in the FsmoRoles column doesn't hold any of the five operations-master roles — completely normal in a multi-DC domain, since most FSMO roles are held by exactly one DC in the whole forest or domain. If you only care about who holds the forest- and domain-wide roles specifically:

Get-ADForest | Select-Object SchemaMaster, DomainNamingMaster
Get-ADDomain | Select-Object PDCEmulator, RIDMaster, InfrastructureMaster

Where the manual approach runs out of road

A one-off script is fine for a single check. It starts to hurt once you actually need to run this regularly:

  • No scheduling. Cron/Task Scheduler can run the script, but now you own the scheduling, the credentials it runs as, and what happens when it silently fails.
  • No history. A CSV export is a snapshot. Was this the same five accounts as last month, or a growing list? A single export can't tell you.
  • No distribution. Getting the report to the right people (security, IT ops, compliance) on a schedule means building that plumbing yourself.
  • Multi-domain/multi-forest pain. Run it once per domain, reconcile the results yourself, and hope naming/OU conventions are consistent across all of them.
  • No alerting. If something changes unexpectedly between runs — an account re-enabled, a privileged group gaining a member — nothing tells you until you happen to run the script again.

None of that is a PowerShell problem. It's what turns a script into a product.

What SysFlint AD does instead

Our SysFlint AD runs the same kind of discovery shown above automatically, on a schedule, entirely inside your own network. No agents on domain controllers, no data leaving your environment. It's free, forever.

  • Scheduled reports by email Daily, weekly, or monthly runs delivered to the right inbox automatically. No Task Scheduler job for you to babysit.
  • Multi-domain and forest coverage Enumerate every domain in the forest in one pass and get one consolidated report instead of one per domain.

If you're currently doing this with a script on a scheduled task, here's the honest comparison between the two, or go straight to the download page.

Get this script, and the rest of them

The script above is part of awesome-it-scripts, SysFlint's free, open-source library of PowerShell scripts for Active Directory and other IT-admin tasks — no signup, no catch, MIT licensed. Grab this one directly from active-directory/Get-ADDomainControllersReport.ps1, or browse the whole thing.

Find every disabled/locked-out/stale/privileged-account script we've published (plus the FAQ that goes with each one) in the repo's active-directory folder. Star it if it's useful — new scripts land there regularly.