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

Tinyproxy and a dragon IT architect from the shadowrun world looking at a large screen with graphs on it

Tinyproxy on Hyper-V – new Ubuntu 24.04

A Linux VM with Proxy, such as tinyproxy, can be used to reduce bandwidth as it caches frequently requested websites. Today we want to configure a Linux VM with a Proxy and deploy…

Spread the knowledge
Read more
COM Port Management and a dragon IT architect from the shadowrun world looking at a com port and a manufacturing floor

Windows – easy COM Port Management without Admin Rights with Windows 10 & 11

COM Port Management with no administrator rights is a challenge. You might have noticed that I am currently involved in IT and OT discussions. During OT modernization, I encountered a…

Spread the knowledge
Read more
Remote Desktop Connection Manager (RDCM) – A Must Have for Homelabs and a dragon IT architect from the shadowrun world looking at his computer monitor without humans

Remote Desktop Connection Manager (RDCM) – A Must-Have for Homelabs

Managing multiple remote connections efficiently is a challenge for IT professionals and homelab enthusiasts alike. Remote Desktop Connection Manager (RDCM) simplifies this process by providing a centralized interface for organizing…

Spread the knowledge
Read more
IT Architect dragon from the shadowrun universe with USB Stick and Rufus theme

Windows Server 2025 – Create bootable USB drives the easy way

To get started with Windows Servers 2025 you need to create a bootable USB drive. This normally is done on a USB Stick. To create a bootable USB Device and…

Spread the knowledge
Read more
A dragon IT Architect in the shadowrun world using an Excel document and the Azure Quick Review Tool

Azure Quick Review 2.04 – High Level Assessments

With Azure Quick Review (azqr) you can quickly make a High Level Assessment of an “Azure Subscription” or “Resource Group”. Installation of Azure Quick Review You can download the files…

Spread the knowledge
Read more
A dragon IT Architect in the shadowrun world using Microsoft Tools like Windows LAPS to secure his datacenter, relaxing and watching a sitcom on TV

Securing Local Administrator Accounts with Windows LAPS: A Get Started Guide for Windows Server Environments

Managing local administrator accounts securely is a critical aspect of maintaining a robust and secure IT environment. With the introduction of the Windows Local Administrator Password Solution (LAPS) in newer…

Spread the knowledge
Read more