Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out which computer is the domain controller in Windows programmatically?

I am looking for a way to determine what the Name/IP Address of the domain controller is for a given domain that a client computer is connected to.

At our company we have a lot of small little networks that we use for testing and most of them have their own little domains. As an example, one of the domains is named "TESTLAB". I have an Windows XP workstation that is a member of the TESTLAB domain and I am trying to figure out the name of the domain controller so that I can go and look to see what users have been defined for the domain. In our lab there is a mix of Windows Server 2000 and Windows Server 2003 (and in reality probably a couple of NT 4 Servers) so it would be nice to find a solution that would work for both.

Looking on the Internet, it looks like there are various utilities, such as Windows Power Shell or nltest, but these all require that you download and install other utilities. I was hoping to find a way to find the domain controller without having to install anything additional.

EDIT If I wanted to write a program to find the domain controller or the users in the current domain, how would I go about doing that?

like image 269
Dorky Engineer Avatar asked Dec 09 '08 20:12

Dorky Engineer


People also ask

How do you find out what domain controller My PC is on?

Find Domain Controller CMD On newer versions, press Windows-Q to launch the apps screen and type cmd.exe into the search bar. Press Enter, and the command prompt launches. Type nslookup and press Enter. Then type set type=all and press Enter.

How do I find the domain controller in PowerShell?

You can use the Get-ADDomainController PowerShell cmdlet to get information about the domain controllers in Active Directory. This cmdlet is a part of PowerShell Active Directory module and requires RSAT installation (onWindows 10 1809 and newer RSAT is installed in a different way).


2 Answers

With the most simple programming language: DOS batch

echo %LOGONSERVER% 
like image 144
MZywitza Avatar answered Sep 24 '22 21:09

MZywitza


In cmd on Windows, type the following commande:

nltest /dclist:{domainname} 

It lists all domain controllers in particular domain

like image 25
Lado Morela Avatar answered Sep 22 '22 21:09

Lado Morela