Solved

Script to find Only empty OU and subOU's nested in a particular OU structure

Posted on 2014-11-07
2
1,033 Views
Last Modified: 2014-11-13
Looking for the most accurate way to find all empty OU and nested Ones within my AD Structure. I dont want the entire forest/domain. Just inside a particular delegated OU.  I have tried many different ways, but when I do a cross-check of the data it is not accurate.  

Cannot use any Third Party tools.
0
Comment
Question by:cgooden01
2 Comments
 
LVL 17

Expert Comment

by:Emmanuel Adebayo
ID: 40428351
To count number of objects in an OU (and sub OU's): use the adfind command
i.e
adfind -b ou=<Require OU to search>,dc=<Yourdomain>,dc=com -f "(objectCategory=*)" -c
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40428373
This will return all empty OU's within a certain OU (Searchbase)

Get-ADOrganizationalUnit -Filter * -SearchBase "OU=My OU,DC=DOMAIN,DC=com" | Where-Object {-not ( Get-ADObject -Filter * -SearchBase $_.Distinguishedname -SearchScope OneLevel -ResultSetSize 1 )} | Select Name,DistinguishedName

Open in new window

1

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

821 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