Beta 42

Research and Development


PowerShell - Finding Domain Controllers

If your computer is logged on to an Active Directory, here is some code to get to your domain controllers. Note that this will raise errors if you are currently not logged on to a domain.

PS> $Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
PS> $Domain.DomainControllers

This lists all domain controllers. To find just one, try this:


And to find all the domain controllers in your forest, simply retrieve all forest domains: