Home » PowerShell » Find What Domain Controller Am I Using?

Find What Domain Controller Am I Using?

Use the windows command echo %logonserver% in cmd and $env:logonserver in the PowerShell, terminal to find the domain controller you are connected to. These commands get the domain controller.

Windows Domain Controller (DC) is a server that is responsible for maintaining a central repository of users, computers, security authentication, authorization information, and other information critical to the Windows network.

In the Windows domain, users, computers, and resources are stored in a centralized database Active directory which is managed by one or more domain controllers.

In this article, we will discuss how to find the domain controller you are connected to using cmd (command prompt) and PowerShell script.

Use cmd to Find Which Domain Controller Am I Using?

Use the command echo %logonserver% on the command prompt (cmd) to get the domain controller you are connected to.

echo %logonserver%

The above command logonserver in cmd checks which domain controller is connected to.

The output of the above echo logonserver in cmd gets the domain controller name that you are connected to.

echo logonserver - find domain controller in cmd
echo logonserver – find domain controller in cmd

Use PowerShell to Get the Domain Controller

In PowerShell, use $env:logonserver to get the domain controller list you are connected to. The environment variable LogonServer contains information about the domain controllers.

$env:LogOnServer

In the above PowerShell script, $env:LogonServer retrieves the domain controllers list.

The output of the above PowerShell script is:

PS C:\> $env:LogOnServer
\\ENGG-PRO

Cool Tip: How to check what active directory groups am I in using PowerShell!

Conclusion

I hope the above article on how to find out which domain controller you are connected to using cmd and PowerShell script is helpful to you.

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