Solved

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

Posted on 2014-11-07
2
1,084 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
[X]
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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

742 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