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.

4 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.

  2. HI,

    You can enter the sub domain name details. The path will be similar to
    $OUpath = ‘OU=Users,OU=,OU=,DC=,DC=’.

Leave a 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 )

Facebook photo

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

Connecting to %s