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.
The correct format is “Import-Module ActiveDirectory” with no space.
This is exporting all user from sub ou’s as well, can you help. i need only users from that OU only
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.
HI,
You can enter the sub domain name details. The path will be similar to
$OUpath = ‘OU=Users,OU=,OU=,DC=,DC=’.