Thursday 3 January 2013

Find domain controller used for logon

I managed to lock out an account today so I was trying to login to the DC, but I couldn't get access to our SharePoint server which meant that I didn't have the environment information at hand, and because this is a new environment, I don't know the name of the servers off the top of my head, which meant that I needed a way to find out a domain controller.

It turns out that this is really easy. Logonserver is an environment variable that contains the domain controller that was used for logging on.

From PowerShell (again with elevated privileges):
Get-ChildItem ENV: | where {$_.Name -eq "logonserver"}
or
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().FindDomainController()  

From a Command Prompt (with elevated privileges):
set logonserver
or 
set L

If you want to get all domain controllers, not just the one you used to logon:
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers

No comments:

Post a Comment