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

Share this:
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.

 

Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).