Quick hint: Listing all users from a specific OU using PowerShell

sans-titre I was asked Today how to create a list of all users from a specific OU with their Display Names and their logon names using PowerShell?

There are several ways to get the results, a simple one when you know the location of the OU (in our example here is apatricio.local/Argentina) is to run the following cmdlet. Make sure that you are logged on a Domain Controller or at least a server with AD tools installed.

Import-Module ActiveDirectory
Get-ADUser -SearchBase "OU=Argentina,dc=apatricio,dc=local" -Filter * -ResultSetSize 5000 | Select Name,SamAccountName

That will give you a list of the users, if you want to export that, just add  | export-csv C:\Argentina-users.csv to the end of the previous cmdlet and open the file afterwards and the same can be open in Excel as well.

Cheers,
Anderson Patricio
http://www.andersonpatricio.ca
http://www.andersonpatricio.org (Portuguese)
Twitter: @apatricio

Leave a Reply

Your email address will not be published. Required fields are marked *