Not sure if this is the right audience, but I’m struggling trying to change the “Last Name” attribute for a bunch of users. I would like to call a csv that I’ve created with usernames and change the last name attribute.
I have this but ONLY need to change last name attribute, please help!
Import AD Module
Import-Module ActiveDirectory
write-Host ‘Starting to update AD Attributes…’ -NoNewline -ForegroundColor Yellow
Import CSV into variable $users
$users = Import-Csv -Path C:users.csv
Loop through CSV and update users if the exist in CVS file
foreach ($user in $users) { #Search in specified OU and Update existing attributes
Get-ADUser -Filter “SamAccountName -eq ‘$($user.samaccountname)’” -Properties * -SearchBase “DC=petsmart,DC=com” |
Set-ADUser -Title $($user.Title) -MobilePhone $($user.MobilePhone) -OfficePhone $($user.OfficePhone) -City $($user.City) -EmailAddress $($user.EmailAddress) -Department $($user.Department) -Office $($user.Office)
}