# Find DC Sever name form Command Line



## TechOz (Jul 19, 2010)

Hi,
Just wondering what command line utility and command to use to find out the distinguished name of the Domain Controllers in teh domain I am logged into. 

Cheers
Jeff


----------



## Dave Atkin (Sep 4, 2009)

Hi Jeff,

If you know that IP Address of the server you can use the nbtstat -a command.

Dave


----------



## Wand3r3r (Sep 17, 2010)

nslookup the domain name
it should list the dns server that replies and list ip addresses associated with that domain name.
You can then nslookup those ip addresses.


----------



## TechOz (Jul 19, 2010)

Thanks for your, muchly appreciated.

Cheers
Jeff


----------



## cluberti (Aug 26, 2010)

If you are running on an OS that contains powershell (Vista, Win7, Win2008 / 2008 R2), you could install the Quest powershell extensions and get the info (and more) from powershell (directly or a script).

#1, download and install the Quest extensions (freeware) on your domain controller or an admin workstation that you can query the domain from as a domain admin:
PowerShell Commands (CMDLETs) for Active Directory by Quest Software

#2, This is an easy PowerShell script to find out where a user has logged on (across an entire domain), and at what time the logon occurred:

```
Add-PSSnapin Quest.ActiveRoles.ADManagement

$UserName = Read-Host "Enter the username to query"

Get-QADComputer -ComputerRole DomainController | foreach {(Get-QADUser -Service $_.Name -SamAccountName $UserName) | select Name, DisplayName, LastLogon, Path} | sort LastLogon | Format-List

Write-Host "List of Domain Controllers and their DNs:"
Get-QADComputer -ComputerRole DomainController | foreach {(Get-QADComputer -ComputerRole DomainController)} | select Name, DN | Format-List
```
#3, Copy the above code into notepad, and save the as QueryUserLogon.ps1 (or whatever file name you choose with the extension .ps1). Then, from a command prompt, execute powershell -file QueryUserLogon.ps1. Enter the username to query when prompted, and it will spit out a list. Note the initial connection can take some time as well as the search, so be advised that it can take some time to prompt for a user name, and take some time to get data and dump out the list - this is normal.

For example, here's what I get in a quick lab I just set up for the user "Administrator". Note you can see where and when the user last logged on, and then the actual DN of that domain controller (which I believe was what you were originally looking for - the DN of the domain controller that the user was logged into):


----------



## ricom (Jun 22, 2011)

I just do it via the command line: 

dsquery server -d (yourdomain) | dsget server -dn


----------

