Home » PowerShell » Get-AdDomainController – Get Domain Controller Info

Get-AdDomainController – Get Domain Controller Info

Get-AdDomainController active directory cmdlet gets one or more active directory domain controllers based on specified domain controller identifier or search criteria, discoverable services criteria.

You can get domain controller information using Identity, filter, or discover parameters in PowerShell Get-AdDomainController cmdlet.

PowerShell Get-AdDomainController
PowerShell Get-AdDomainController

In this article, I will explain how to use PowerShell Get-AdDomainController in Active Directory to get available domain controller in current domain using discovery, get domain controller in a given domain, get a global catalog in the current forest using discovery.

Get-AdDomainController Syntax and Parameters

Get-AdDomainController gets one or more domain controller information using filter, discover or identity parameter.

Syntax:

 Get-ADDomainController [[-Identity] ADDomainController]
  [-Credential PSCredential] [-Server string]
  [-AuthType {Negotiate | Basic}] [CommonParameters]

Get-ADDomainController -Discover [-AvoidSelf] [-DomainName string]
  [-ForceDiscover] [-MinimumDirectoryServiceVersion {Windows2000 | Windows2008}]
  [-NextClosestSite string] [-Service ADDiscoverableService[]]
  [-SiteName string] [-Writable ][-AuthType {Negotiate | Basic}] [CommonParameters]

Get-ADDomainController -Filter string [-Credential PSCredential]
    [-Server string] [-AuthType {Negotiate | Basic}] [CommonParameters]

Parameters:

AuthType – It specifies the authentication method to use. AuthType parameter accepts either Basic (or 1) or Negotiate (or 0). It has Negotiate default authentication method.

SSL (Secure Socket Layer) connection is required to use the Basic Authentication method.

Credential PSCredential – It specifies user credentials required to perform Get-AdDomainController. It default accepts the credentials of logged-on users.

To use the Credential parameter, use username as User1 or domain\User1 or you can create and use PSCredential object by using Get-Credential cmdlet.

-Identity – It specifies Active Directory domain controller object using the distinguished name, GUID , security identifier or SAMAccountName

Filter – It specifies a query string (PowerShell Expression Language Syntax) to retrieves Active Directory objects. PowerShell wildcards other * are not supported by filter syntax.

-AvoidSelf – It specifies not to return a self computer or current computer as a domain controller. If the current computer is not a domain controller, this parameter will be ignored.

-Discover – Gets domain controller that meets the conditions specified by parameter.

-DomainName – Specified domain to search. Get-AdDomainController cmdlet locates a discoverable domain controller in the specified domain name.

Let’s understand PowerShell Get-AdDomainController cmdlet with examples to get domain controller using filter, identity, or discover search criteria.

Get Domain Controller in Current User Session

You can get available domain controller information in the current user session using Get-AdDomainController cmdlet as below

Get-AdDomainController

The output of above PowerShell script, returns available domain controller in current user session, output as below

PS C:\Windows\system32> Get-ADDomainController


ComputerObjectDN           : CN=ENGG-PRO,OU=Domain Controllers,DC=SHELLPRO,DC=LOCAL
DefaultPartition           : DC=SHELLPRO,DC=LOCAL
Domain                     : SHELLPRO.LOCAL
Enabled                    : True
Forest                     : SHELLPRO.LOCAL
HostName                   : ENGG-PRO.SHELLPRO.LOCAL
InvocationId               : c955b45a-090a-42b7-aef9-4490b0d2b5d1
IPv4Address                : 1.1.1.1
IPv6Address                :
IsGlobalCatalog            : True
IsReadOnly                 : False
LdapPort                   : 389
Name                       : ENGG-PRO
NTDSSettingsObjectDN       : CN=NTDS Settings,CN=ENGG-PRO,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=SHELLPRO,DC=LOCAL
OperatingSystem            : Windows Server 2019 Datacenter
OperatingSystemHotfix      :
OperatingSystemServicePack :
OperatingSystemVersion     : 10.0 (17763)
OperationMasterRoles       : {SchemaMaster, DomainNamingMaster, PDCEmulator, RIDMaster...}
Partitions                 : {DC=ForestDnsZones,DC=SHELLPRO,DC=LOCAL, DC=DomainDnsZones,DC=SHELLPRO,DC=LOCAL, CN=Schema,CN=Configuration,DC=SHELLPRO,DC=LOCAL,
                             CN=Configuration,DC=SHELLPRO,DC=LOCAL...}
ServerObjectDN             : CN=ENGG-PRO,CN=Servers,CN=Default-First-Site-Name,CN=Sites,CN=Configuration,DC=SHELLPRO,DC=LOCAL
ServerObjectGuid           : e6071fc7-2c78-4fcc-ac81-022db678615a
Site                       : Default-First-Site-Name
SslPort                    : 636

Cool Tip: How to get aduser employeeid in PowerShell!

Get Available Domain Controller in Given Domain

You can get available domain controller in given domain name using discovery as below

 Get-ADDomainController -Discover -Domain "SHELLPRO.LOCAL"

Above command uses Get-AdDomainController to get available domain name specified by Domain parameter and using Discover parameter.

Get Available Domain Controller in Current Domain

You can get available domain controller information in current domain using Discovery criteria as below

Get-AdDomainController -Discover

Get Domain Controller using NetBIOS name

If you want to get available domain controller using its NetBIOS name, use Get-AdDomainController with Identity parameter as below

 Get-ADDomainController -Identity "ENGG-PRO"

In the above command, NetBIOS name is ENGG-PRO, using Identity parameter, Get-AdDomainController returns available domain controller information.

Get Domain Controller using IP Address

If you want to get domain controller using IP address, specify IP address using Identity parameter in Get-AdDomainController to return available domain controller information as below

Get-ADDomainController -Identity "10.1.0.5"

Cool Tip: How to get list of ad groups for user in PowerShell!

Get a Domain Controller in Site

You can get domain controller information available in the specified site using Site parameter in Get-AdDomainController active directory cmdlet as below

Get-AdDomainController -Discover -Site "Default-First-Site-Name"

In the above PowerShell script, it returns available domain controller information in the site specified by Site parameter, output as below

PS C:\Windows\system32> Get-ADDomainController -Discover -Site "Default-First-Site-name"


Domain      : SHELLPRO.LOCAL
Forest      : SHELLPRO.LOCAL
HostName    : {ENGG-PRO.SHELLPRO.LOCAL}
IPv4Address : 1.1.1.1
IPv6Address :
Name        : ENGG-PRO
Site        : Default-First-Site-Name

If you have a requirement to get an available domain controller in the given site using Force discovery, run the below command with the ForceDiscover parameter

Get-ADDomainController -Discover -Site "Default-First-Site-name" -ForceDiscover

Get Global Catalog in the Current Forest

You can get global catalog in the current forest using discovery as below

 Get-ADDomainController -Discover GlobalCatalog

Cool Tip: How to get aduser in multi domain forest in PowerShell!

Get Domain Controller using DNS HostName

If you want to get available get domain controller using its DNS Host Name, run below command

Get-ADDomainController -Identity "ENGG-PRO.SHELLPRO.LOCAL"

In the above command, DNS Host Name is specified by Identity parameter and it returns domain controller information.

Cool Tip: How to get adcomputer operating system in PowerShell!

Get List of Read Only Domain Controllers (RODC)

To display list of read only domain controllers , use the below command

Get-ADDomainController -Filter {IsReadOnly -eq $true} | Select Name, Domain,IsReadOnly

In the above PowerShell command, Get-AdDomainController active directory cmdlet use Filter parameter to get list of read only domain controller where IsReadOnly the attribute is equal to $true

It displays list of read-only domain controllers name, domain, IsReadOnly on the console.

Get Domain Controller in Site where name starts with

If you want to get list of domain controllers on the site where Site name starts with SHELL*, run below command to display a list of DC

 Get-ADDomainController -Filter {Site -like 'Default*'} | Select Name, Domain,Site

In the above PowerShell script, Get-AdDomainController active directory cmdlet filter DC where site name begins with Default *

It displays list of domain controller on the site as below

PS C:\Windows\system32> Get-ADDomainController -Filter {Site -like 'Default*'} | Select Name, Domain,Site

Name     Domain         Site
----     ------         ----
ENGG-PRO SHELLPRO.LOCAL Default-First-Site-Name

Cool Tip: How to get computer name and domain name in PowerShell!

Conclusion

I hope the above details article on using PowerShell Get-AdDomainController with different examples helpful to you.

You can use Get-AdDomainController to find domain controllers by certain criteria or to find the availability of domain controllers.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment