Creating Active Directory Users from a CSV With PowerShell

In order to meet our licensing agreement with MSFT, I needed to get the rest of our users into Office 365 in a hurry, the trouble was, these folks were not on our on prem server, nor in our AD environment at all. Therefore, we decided to create shell accounts for these addresses, and import their mail into the shell accounts. Here is the script I used to create the shell accounts:

1st, have a spreadsheet called users.csv with the firstname and lastname in separate columns called givenname, and surname… it should look like this:


givenname     surname

joe                   schmoe

test                  guy


And the CSV should be saved to “c:” or you can change the script to match your location.

#Start Script:

$UserList=IMPORT-CSV C:Users.csv

# Step through Each Item in the List

FOREACH ($Person in $UserList) {

# Build Username from First name and Last Initial


# Put our Domain name into a Placeholder, who wants all that typing?


# Build the User Principal Name Username with Domain added to it


# Create the Displayname (firstinitiallastname)

$Name=$Person.givenname.substring(0,1)+” “+$Person.surname

# Create User in Active Directory

NEW-QADUSER –FirstName $Person.Firstname –Lastname $Person.Lastname –Name $DisplayName $Name –SamAccountName $Username –UserPassword ‘1NewPassword’ –UserPrincipalName $UPN –Name $Name –ParentContainer ‘domain.local/Division/Contoso’

#end script

There is an excellent writeup on the script I based this one off of one over at:


This is a pretty awesomely helpful site, and there are many more useful scripts there.

As always, use scripts at your own risk, and understand them prior to using them in your environment!


Leave a Reply

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