Export user list from AD using Powershell

It’s sometimes very useful to be able to quickly export a list of users from AD, into a spreadsheet. This is something that teachers ask me to do regularly, so they have a list of student usernames in their class / year.

Here’s how – Open powershell and type the below:

Get-ADUser -Filter * -SearchBase “ou=Ou,dc=contoso,dc=com” -Properties * | Export-Csv  “c:\somefile.csv”

Change the “OU=” fields to be the path of the accounts in AD by inserting the names of your organisational units. You can add/remove the “OU=” at will, so there are as many as you need. You’ll need one for each OU in the path, and you’ll want to start at the last one first.

You’ll also need to replace “dc=” with the domain name. If your domain name is SchoolName.local you’ll need a “dc=” for the SchoolName section and another for the local section.

See the example below for all users in the AD domain SchoolName.local in the OU “Users > Students > 2012 Intake”:

Get-ADUser -Filter * -SearchBase “ou=2012 Intake,ou=Students,ou=Users,dc=SchoolName,dc=local” -Properties * | Export-Csv  “c:\somefile.csv”

Leave a Reply