PowerShell: List users from a specific OU


Here is the command to list all users from specific OU in Active Directory.

Import-Module ActiveDirectory
Get-ADUser -Filter * -SearchBase “ou=ouname,dc=company,dc=com”

If you don’t know the OU name in distinguished name,

1. open Active Directory Users and Computers, enable Advanced Features in the menu, open the OU properties, go to Attribute Editor and open distinguishedName property and Select the OU distinguished name, copy/paste it to the above Get-ADUser command.

OR

2. Type this command: Get-ADOrganizationalUnit -Filter * | Select-Object DistinguishedName. Select the OU distinguished name, copy/paste it to the above Get-ADUser command.

Advertisements

3 thoughts on “PowerShell: List users from a specific OU

  1. Get-ADUser -Filter * -SearchBase “ou=ouname,dc=company,dc=com”, this will export all users also from sub Ou, which i dont want. how to export only from one OU not from sub Ou’s under it.

Leave a Reply to upwan Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s