Powershell – List all domain controllers and more for the new Windows Server 2025

How do you create a list of all domain controllers (DCs) with a few commands and write it to a CSV file? Comma-separated values (CSV) is a text file format that uses commas to separate values, and newlines to separate records.

Use Powershell to list all DCs and export to a CSV

We start Powershell ISE first and change to our desired directory for the export. I always change there to Documents or to the download area.

If you don’t work much with command lines, you should get into the habit of pressing the “Tab” key known from Linux to complete commands and paths.

For example, it is sufficient to enter Get-AdD and press Tab twice to make our current command “Get-AdDomainController” visible. In ISE you also have the support of the graphical interface, which is why I personally prefer to work with the ISE module than with the standard Powershell.

Powershell ISE für Get-AdDomainController
ISE für Get-AdDomainController

As you can see in the screenshot, I have already changed the directory and am preparing the command. We now enter the following command.

Get-AdDomainController -filter * | Select Name, Domain, Forest, IPv4Address, Site |export-csv -path >alldc.csv

If you now open the file in the path, you will find the following content there

#TYPE Selected.Microsoft.ActiveDirectory.Management.ADDomainController
"Name","Domain","Forest","IPv4Address","Site"
"DC-2025-WEU","domain.test","hartiga.test","10.0.2.5","Default-First-Site-Name"

There is now only one DC in the test environment, but in larger environments this can be over 100 and you save a lot of work if you transfer this to Excel.

In Excel, simply go to Data -> From Text/CSV and select the created alldc.csv file. This then creates the following import, which you can then process further in Excel to synchronize groups or data.

Import the list of all domain controllers to Excel
Import the list of all domain controllers to Excel

You can add other attributes to the command after the | Select. The list of parameters can be found here at Microsoft.

Which DC am I connected to?

This can be done with the same command and the parameter -Discover

Get-ADDomainController -Discover

This is particularly useful if you want to check from the Powershell whether the AD site and service configuration is correct.

This uses the same technique that is used to find the “next” DC when you first log on.

You can also do this in the “classic” cmd, simply enter “set” and then search for the parameter “LOGONSERVER”.

Verify if Active Directory Domain Services are running

Get-Service adws,kdc,netlogon,dns

Get Details about your DC

Get-ADDomainController

Get Details about your Active Directory Domain

Get-ADDomain ad.hartiga.de

Replace ad.hartiga.de with the domain you want to get details for.

Count All computers by Operating System in your AD Domain

This will give you a count of all the computers and group them by operating system. It’s a great command to give you a quick inventory of computers in AD.

Get-ADComputer -Filter "name -like '*'" -Properties operatingSystem | group -Property operatingSystem | Select Name,Count

Backup all GPOs in the Domain

If you are working with GPOs and make changes, I would recommend to always run a backup first. The following command will do that for you and you can choose the path to save the files to.

Backup-Gpo -All -Path E:GPObackup

Conclusion

Using the Command line is a powerful toolset, that can easily help us with information. Especially reproducing the login results to check for AD site and service configuration is a quick win. Just run “Get-ADDomainController -Discover”.

If you quickly need to check on uptime, there is a command to do this here.

Avatar for Andreas Hartig
Andreas Hartig - MVP - Cloud and Datacenter Management, Microsoft Azure

Related Posts

the IT Operations dragon looking at multiple screens with Group Policies on them and the GPO Policy Analyzer checking them all

How to use the GPO Policy Analyzer

Managing Group Policy Objects across a complex Active Directory environment has always been a challenge. Administrators often inherit hundreds of GPOs with overlapping configurations, stale settings, and hidden conflicts. Finding…

Read more
WAU Happy Dragons crazy about 110 percent security

Schedule Winget Auto Updates for operational usage

Deploying Winget Auto Updates (WAU) gives you a functional update baseline, for full functionality we need to configure more to get ready for production. If servers query the Winget repository…

Read more
WAU Happy Dragons about improved security

Centralized Software Patch Management: Deploying Winget Auto Updates (WAU) via Active Directory GPO

Deploying Winget Auto Updates for Software Patch Management for managing third-party software updates across an IT infrastructure typically requires expensive enterprise solutions. This article provides a technical guide on how…

Read more
Gemini Generated Image 6s2cz6s2cz6s2cz6

Active Directory Planning Tool: Mapping Structures and Delegations with SMAD-X

Using an Active Directory Planning Tool is key for understanding complex Active Directory environments and often requires more than what traditional management consoles can provide. While tools such as Active…

Read more
Dragons looking at AccountLockout Tool

AD Account Lockout (Free Tool)

The AD Account Lockout tool is free and very valuable in troubleshooting account lockouts in Active Directory. This is a task as old as the directory service itself. Even in…

Read more
IT Architect doing Active Directory Visualization

Active Directory Visualization (Free Tools)

Designing and documenting Active Directory (AD) structures is always a long and complex exercise. Historically, this required either building full lab environments or settling for static Visio diagrams that became…

Read more