List users in a OU using powershell with dsquery


  • I would like to list the all the users in a OU in active directory 2008 R2 my OU is located in OU=Sales,OU=Usuarios,DC=mycompany,DC=ecu,DC=co
    Tuesday, November 22, 2011 11:06 PM


  • I assume you want the sAMAccountName of the user (the "pre-Windows 2000 logon" name). Using Get-ADUser:

    Get-ADUser -filter * -SearchBase "ou=West,dc=MyDomain,dc=com" | Select sAMAccountName

    and using dsquery:

    dsquery user "ou=West,dc=MyDomain,dc=com" | dsget user -samid

    In both cases you can redirect the output to a txt file.

    Richard Mueller - MVP Directory Services
    Wednesday, November 23, 2011 2:46 AM

All replies