I'm faced with a situation where I have a CSV file containing all the details of my test script AD users. This includes information like ID number, First Name, Last Name, SamAccountName, and OU Path.
After creating these users, it turns out that some are missing the userPrincipalName attribute while the rest of the attributes are present.
To rectify this issue, I aim to write a script that will add the userPrincipalName to all users.
Here's what I've attempted so far:
$CSVusers = import-csv C:\CorpCSV.csv
$Users = $CSVusers.SamAccountName
$Users | % {Get-ADUser $_ | Set-ADUser $_ -userPrincipalName $Users}
Although the script ran without errors, it seems that nothing changed as the userPrincipalName attribute is still empty in Active Directory (View attached image).