Many files are in a folder, and you must add a prefix or suffix to…
Get all Domain Controllers with PowerShell
You want to raise the Active Directory domain and forest functional levels. But, before doing so, you need to check which Domain Controllers are running in the organization and if they run at least a specific Operating System. In this article, you will learn how to get all Domain Controllers in the forest with PowerShell.
Table of contents
- Get-ADDomainController cmdlet
- Install Active Directory module for Windows PowerShell
- Get all Domain Controllers with full details
- List all Domain Controllers and Operating System
- Get all Domain Controllers and IP address
- Count Domain Controllers
- Filter Domain Controllers
- Export all Domain Controllers to CSV file
- Conclusion
Get-ADDomainController cmdlet
The Get-ADDomainController cmdlet is an excellent method to list all the Domain Controllers in the forest.
PS C:\> Get-ADDomainController -Filter *
Install Active Directory module for Windows PowerShell
Run PowerShell as administrator and run the below command to install Active Directory module for Windows PowerShell.
PS C:\> Add-WindowsFeature RSAT-AD-PowerShell
Important: You need to install the Active Directory module for Windows PowerShell. Otherwise, it can’t load the Get-ADDomainController cmdlet, and an error appears.
Get all Domain Controllers with full details
The Get-ADDomainController cmdlet shows all the Domain Controllers in the output.
In our example, we only copied the first section of the output, which is the Domain Controller DC01-2019.
PS C:\> Get-ADDomainController -Filter *
ComputerObjectDN : CN=DC01-2019,OU=Domain Controllers,DC=exoip,DC=local
DefaultPartition : DC=exoip,DC=local
Domain : exoip.local
Enabled : True
Forest : exoip.local
HostName : DC01-2019.exoip.local
InvocationId : b44dc8cf-ce37-4046-b908-8504ff700efe
IPv4Address : 192.168.1.51
IPv6Address :
IsGlobalCatalog : True
IsReadOnly : False
LdapPort : 389
Name : DC01-2019
NTDSSettingsObjectDN : CN=NTDS Settings,CN=DC01-2019,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=exoip,DC=local
OperatingSystem : Windows Server 2019 Standard
OperatingSystemHotfix :
OperatingSystemServicePack :
OperatingSystemVersion : 10.0 (17763)
OperationMasterRoles : {SchemaMaster, DomainNamingMaster, PDCEmulator, RIDMaster...}
Partitions : {DC=ForestDnsZones,DC=exoip,DC=local, DC=DomainDnsZones,DC=exoip,DC=local, CN=Schema,CN=Configuration,DC=exoip,DC=local, CN=Configuration,DC=exoip,DC=local...}
ServerObjectDN : CN=DC01-2019,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=exoip,DC=local
ServerObjectGuid : 01218cb8-7c17-4d26-bb2a-cc80bc43059c
Site : Default-First-Site-Name
SslPort : 636
List all Domain Controllers and Operating System
We can add only the objects we want to display in the output.
PS C:\> Get-ADDomainController -Filter * | ft Name,Hostname,OperatingSystem,Enabled
Name Hostname OperatingSystem Enabled
---- -------- --------------- -------
DC01-2019 DC01-2019.exoip.local Windows Server 2019 Standard True
DC02-2019 DC02-2019.exoip.local Windows Server 2019 Standard True
Get all Domain Controllers and IP address
Get a list of Domain Controllers, including their IP address.
PS C:\> Get-ADDomainController -Filter * | ft Name,IP*
Name IPv4Address IPv6Address
---- ----------- -----------
DC01-2019 192.168.1.51
DC02-2019 192.168.1.52
Count Domain Controllers
Get a count of all the Domain Controllers.
PS C:\> Get-ADDomainController -Filter * | Select-Object name | Measure-Object | Select Count
Count
-----
2
Filter Domain Controllers
Filter the Domain Controllers and list only the DCs with the Windows Server 2019 Operating System.
PS C:\> Get-ADDomainController -Filter {OperatingSystem -like "Windows Server 2019*"} | ft Name,Hostname,OperatingSystem,Enabled
Name Hostname OperatingSystem Enabled
---- -------- --------------- -------
DC01-2019 DC01-2019.exoip.local Windows Server 2019 Standard True
DC02-2019 DC02-2019.exoip.local Windows Server 2019 Standard True
Export all Domain Controllers to CSV file
You can export a list of the Domain Controllers to a CSV file.
PS C:\> Get-ADDomainController -Filter * | Select-Object Name,Hostname,IP*,Enabled | Export-Csv C:\temp\All-Domain-Controllers.csv -NotypeInformation
Open the CSV file with your favorite application. In our example, it’s Microsoft Excel.
That’s it!
Read more: Get Organizational Units with PowerShell »
Conclusion
You learned how to get all Domain Controllers with PowerShell. The PowerShell cmdlet Get-ADDomainController is an excellent way to list all Domain Controllers in the organization.
Did you enjoy this article? You may also like Export AD group members with PowerShell. Don’t forget to follow us and share this article.
thanks for all! 😀
i try it:
Get-ADDomainController | ft Name,Hostname,OperatingSystem,Enabled
but the answer indicates only one DC (only DC where i ran command shell!) in my AD! but there are 3 DC!
:/
You’re welcome, Alessio.
I adjusted the commands slightly, and it should work now. Thanks for letting me know.