Find OU with most computers in Active Directory

Posted on 2009-03-30
Last Modified: 2012-05-06
Is there an easy way to find out which OU in Active Directory contains the most computers?

What about just a report of some kind to show the # of computers based on the container they're in, instead of a just a long list of all computers in Active Directory?

Using Windows XP and active directory is on windows 2003 server
Question by:garryshape
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 57

Expert Comment

by:Mike Kline
ID: 24019518
I use a tool called adfind to get the counts
So for the domain for instance
adfind -b dc=yourdomain,dc=com -f "objectcategory=computer" -c
I'm not sure if it can go and count per OU but I'll test and if I find a way using adfind I'll let you know
LVL 71

Accepted Solution

Chris Dent earned 500 total points
ID: 24019588

PowerShell can though with a small amount of code.

You'd need this;

And this:

To be able to run the little script below (it'll just paste into the Quest PowerShell window).

Get-QADObject -Type OrganizationalUnit | %{
  $ComputerCount = (Get-QADObject -SearchRoot $_.DN -Type Computer -Scope OneLevel).Count
  If ($ComputerCount) { $_ | Select-Object DN, @{n='ComputerCount';e={ $ComputerCount }} } }

Open in new window

LVL 71

Expert Comment

by:Chris Dent
ID: 24019613

The second "GetQAD-Object" should have been substituted with Get-QADComputer as below. Although it really doesn't make much difference.

Get-QADObject -Type OrganizationalUnit | %{
  $ComputerCount = (Get-QADComputer -SearchRoot $_.DN -Scope OneLevel).Count
  If ($ComputerCount) { $_ | Select-Object DN, @{n='ComputerCount';e={ $ComputerCount }} } }

Open in new window

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

LVL 57

Expert Comment

by:Mike Kline
ID: 24019634
I had a feeling powershell could do it
Ok going to see Brandon speak in April. I'm going to get the powershell bug :)
LVL 71

Expert Comment

by:Chris Dent
ID: 24019647

Sounds like fun, I hope you get a lot out of it :)


Author Closing Comment

ID: 31564329
Thanks it works great

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Finding machines using a specific DNS server 6 60
Changing logon server question 5 61
AD Tool/Script Populate Security Groups Automatically 8 35
DNS/WINS in a domain 10 39
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question