A
A
Alina Andreeva2017-11-15 17:32:15
PowerShell
Alina Andreeva, 2017-11-15 17:32:15

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

1 answer(s)
N
Newerindian, 2017-11-15
@linacat2305

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 question

Ask a Question

731 491 924 answers to any question