Answer the question
In order to leave comments, you need to log in
How to list empty OUs?
I work in a large organization and the Active Directory structure contains a large number of organizational units. How can I do a AD search and display a list of OUs that do not contain child OUs, accounts, computers, and groups (that is, empty ones)? Dancing with Google, alas, did not radically help.
Answer the question
In order to leave comments, you need to log in
You can try this:
Get-ADOrganizationalUnit -filter * | select-object DistinguishedName, @{name = 'objCount'; expression={(Get-ADObject -filter * -SearchBase $_).count}} | Where-Object{$_.objCount -eq $null} | Format-Table -AutoSize
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question