Learn about Windows PowerShell
Summary: Use a single line Windows PowerShell command to list all users in an OU.
How can I list all users in a particular organizational unit (OU)?
Use the Get-ADUser cmdlet from the ActiveDirectory Module (available from the RSAT tools). Specify the SearchBase as the name of the OU, and use a wildcard pattern for the Filter.
Get-ADUser -Filter * -SearchBase "ou=testou,dc=iammred,dc=net"
Note In Windows PowerShell 3.0, you do not have to load a module prior to using it.
Used that one just last week, I had to check the number of users in a OU. You can use: (Get-ADUser -Filter * -SearchBase "ou=testou,dc=iammred,dc=net").Count
Additional,
If don't want list the sub OU in target OU, can use -SearchScope parameter.
@Nico Martens that is a good tip, and a great way to show how to expand the code.
@Larry Song CN yes, the SearchScope is a great way to control searching. Thank you for sharing.