Solved

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

Posted on 2014-11-07
2
931 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 16

Expert Comment

by:Emmanuel Adebayo
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now