Powershell – AD – Get-ADUser from text list

Detailing how to get certain AD details based on a text list containing usernames.


  1. The content of the user list should be in the below formatuserlist
  2. The Active Directory Module will be required. You can install that by following this post.
  3. There are many properties that can be returned from an AD user object, to see all of them you can run “Get-ADUser $name -properties *”
  4. Extra parameters used with Export-CSV explained
    1. -Append = Appends each entry to the CSV
    2. -NoTypeInformation = Do not include the type information at the top of the CSV

Code description

  1. The $UserNamesList variable will be populated with the content of the text file
  2. The script will iterate through the list, perform a get-aduser and then export the details to CSV.


$UserNamesList = get-content -path "C:\temp\users.txt"
$exportPath = "C:\temp\Users_Detailed.csv"

foreach ($name in $UserNamesList){

Get-ADUser $name -properties * | select GivenName, Surname, SamAccountName, EmailAddress, Title, Company, Department, Country, st, Office, OfficePhone, MobilePhone, LastLogonDate, createTimeStamp, Enabled | Export-CSV $ExportPath -Append -NoTypeInformation


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s