Script to populate AD fields

New Contributor


I have a bunch of active user accounts where only the username field has been populated.  I need to populate the First Name, Last Name and E-Mail fields.

Can anyone help me with a script I could use which could find the username in a csv file and add the missing fields in AD?

I'm thinking csv file would contain username,firstname,lastname,email ?

4 Replies
best response confirmed by BuckMacD (New Contributor)



If you have a .csv file with these lines in them (only added as example, you can add as much as you want of course), you can use the script below to put values in Active Directory users: 








foreach ($user in Import-Csv C:\Scripts\users.csv -Delimiter ',') {
Set-ADUser -Identity $user.username -GivenName $user.firstname -Surname $user.lastname -EmailAddress $





But you can add more in your csv of course and use the other parameters in Set-Aduser (

Thanks a lot @Harm_Veenstra. I'll give this a shot on Monday. :thumbs_up:

No problem, let us know if it worked out for you and have a good weekend!

Thanks @Harm_Veenstra 

That seems to be working well.  Tried it out on a small subset of test users and it does what it should.

I'm going to request a bit more user info from our MIS team and use that to populate some more useful fields in AD (description, department etc)

I'm still a bit of a noob with Powershell but didn't expect a simple one-liner to do everything I needed!

Cheers for your help!