Feb 25 2022 11:31 AM
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 ?
Feb 25 2022 12:23 PM - edited Feb 25 2022 12:42 PM
Solution
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...)
Feb 25 2022 12:37 PM - edited Feb 25 2022 12:39 PM
Thanks a lot @Harm_Veenstra. I'll give this a shot on Monday. :thumbs_up:
Feb 25 2022 12:42 PM
Feb 28 2022 07:43 AM
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!
Feb 25 2022 12:23 PM - edited Feb 25 2022 12:42 PM
Solution
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...)