Take the 2-minute tour ×

I would like to list all machines names from a domain and their current ip if they are online. I am thinking of using dsquery on the domain controller to list all machines.

I am wondering:

  • Will it work if i have distributed domain controllers on various locations?
  • Do i need to run it on the Primary Domain Controller?
  • Is there an alternative?
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
  1. Yes. You usually run a query against one domain controller and not all of them. The data is replicated to all sites. The query represents the state of the current site which may differ to another one due to replication times. To get the computer accounts you don't need a dns-server but the DNS Zones might not be up to date as Mathias said.
  2. No, reading computer-accounts from an active directory can be done from any machine in the domain(except reading is denied for some reason, which usually is not the case). The same is true for dns-queries
  3. Yes. See below

I recommend using powershell. When you have a Windows 7 or Vista machine (with domain join) you can install RSAT and use the provided cmndlets

Get-ADComputer -Filter * | Select-Object DNSHostName, @{name="Ip";Expression={(Test-Connection $_.DNSHostname -Count 1).IPV4Address.IPAddressToString}}

This code gives you the dnsname and the current ipv4-address (if running; using the cmdlet test-connection).

share|improve this answer
Looks really promising and straightforward. Will try it. –  elhoim Feb 8 '12 at 8:50
add comment

3 answers to 3 questions:

  1. You might experience that DNS Zones are not up to date if you employ special replication schedules between your sites.
  2. You don't need to run it against the PDC Emulator (or PDC if you, god forbid it, still use NT4), but if you want to retrieve information on computers in for than one domain in the forest, you might want to run it against the Global Catalog
  3. If you use Microsoft DHCP in your local network, use the following command to show active client leases: Netsh dhcp server scope show clients

I would probably use VBScript or PowerShell to do the following:

  1. Perform an LDAP search against the Global Catalog, filtering for the operatingsystem attribute,
  2. For each returned record, perform DNS lookup against the local DNS server
  3. Query each computer with WMI (just a simply query) to ensure that it's online
share|improve this answer
Additionally, you could run psloggedon to retrieve the name of the currently logged on user. BTW: DNS records might be out of date if DNS updates are not configured correctly. –  the-wabbit Feb 7 '12 at 10:08
"or PDC if you, god forbid it, still use NT4" had to smile reading this. But I guess OP is not using NT4 because he used the active-directory tag. –  Tom Feb 7 '12 at 10:53
@Tom yeah, figured that too, but reading the phrase "Primary Domain Controller" without "Emulator" at the end just sent shivers down my spine :-) –  Mathias R. Jessen Feb 7 '12 at 16:46
@MathiasR.Jessen Yeah, I know that feeling :-) –  Tom Feb 9 '12 at 7:40
add comment

Your Answer


