Forum Discussion
Script to populate AD fields
- Feb 25, 2022
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)
Thanks a lot Harm_Veenstra. I'll give this a shot on Monday. 👍
- BuckMacDFeb 28, 2022Copper Contributor
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!