?
Solved

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

Posted on 2014-11-07
2
Medium Priority
?
1,176 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 18

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 2000 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

Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 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