Forum Discussion
BuckMacD
Feb 25, 2022Copper Contributor
Script to populate AD fields
Hi,
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 ?
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:
username,firstname,lastname,email
testuser1,test,user1,Emailaddress
foreach ($user in Import-Csv C:\Scripts\users.csv -Delimiter ',') { Set-ADUser -Identity $user.username -GivenName $user.firstname -Surname $user.lastname -EmailAddress $user.email }
But you can add more in your csv of course and use the other parameters in Set-Aduser (https://docs.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps)
4 Replies
Sort By
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:
username,firstname,lastname,email
testuser1,test,user1,Emailaddress
foreach ($user in Import-Csv C:\Scripts\users.csv -Delimiter ',') { Set-ADUser -Identity $user.username -GivenName $user.firstname -Surname $user.lastname -EmailAddress $user.email }
But you can add more in your csv of course and use the other parameters in Set-Aduser (https://docs.microsoft.com/en-us/powershell/module/activedirectory/set-aduser?view=windowsserver2022-ps)
- BuckMacDCopper Contributor
Thanks a lot Harm_Veenstra. I'll give this a shot on Monday. 👍
- No problem, let us know if it worked out for you and have a good weekend!