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.

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

Related Posts

Winget and IaC SystemEngineerDragon

WinGet and IaC – Take Winget to the next level

WinGet and IaC are maybe your next step to automate your environment. In the past, managing third-party applications on Windows meant 3rd party tools or gathering MSI installers on network … Read more

Spread the knowledge
Read more
Dragon IT Operations logfile tailing using Klogg

Tail for log files with Windows – 2026 Edition

I view a lot of log files—probably more than I’d like to admit. Whether it’s troubleshooting a hybrid infrastructure issue or debugging a cloud deployment, I always look for the … Read more

Spread the knowledge
Read more
dragon it system engineer grc benchmark

Windows DNS Performance Testing

DNS issues don’t always show up as clear outages. Often they show up as annoying browser behaviour like “random delays on first page load”, “sometimes it works, sometimes it spins”, … Read more

Spread the knowledge
Read more
IT Security Dragon reading Windows Event Logs

Windows Server Event Log and Event Log Policies

Windows Server Event Log for most teams are only used when something already smells like incident:💥 DC misbehaving,💥 file server “mysteriously slow”,💥 SOC asking for “all the logs you have … Read more

Spread the knowledge
Read more
notepad addons 2025 hero

Notepad++ – Most important AddOns 2025

Notepad++ is my favourite notebook and editor is actually perfect, but it can always be better. For this reason, there are a few “quality of life” improvements that I use … Read more

Spread the knowledge
Read more
Technitium DNS Server on Windows

Homelab – Build a robust DNS foundation – Part 2 using Technitium DNS Server on Windows

Let’s create an improved version of the Technitium DNS server for Windows. Some time ago, I wrote a DNS guide to help you get started with your home laboratory. This … Read more

Spread the knowledge
Read more