Link to home
Start Free TrialLog in
Avatar of Hussain Arif
Hussain ArifFlag for Pakistan

asked on

How to Count Sub Ou's Under the Specific OU

How can I Count the Sub Ou's Under the Specific OU in active directory for example Root OU: Test Ou1 and sub OU's are: Test Ou2, test OU3, Test OU4
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

(Get-ADOrganizationalUnit -SearchBase "OU=Root,DC=Domain,DC=com" -Filter * -SearchScope Subtree).Length

Open in new window

Shaun's code will get you a count, but do make anote that with -SeachScope Subtree you will get all OUs under the root and their children.  You may want to use -SeachScope OneLevel to count just the direct children.

(Get-ADOrganizationalUnit -SearchBase "OU=Root,DC=Domain,DC=com" -Filter * -SearchScope OneLevel).Length

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.