You could continue adding the individual parameters and values to the Set-ADUser cmdlet, making it longer and more cumbersome to deal with, of you could use a hash to assemble the parameters and values and use "splatting" to keep the clutter down.
I also added some minimal error handling.
Import-Csv -Path "C:\temp\adinfo.csv" |
ForEach-Object {
# properties from the csv
$acct = $_.samaccountname # needed for error message
$props = @{
EmployeeID = $_.EmployeeID
Office = $_.Office
title = $_.title
Department = $_.Department
emailaddress = $_.emailaddress
officephone = $_.officephone
manager = $_.manager
company = $_.company
}
Try {
Get-ADUser -Identity $_.SamAccountName -Properties * -ErrorAction STOP|
Set-ADUser @props -ErrorAction STOP
}
Catch {
Write-Host "User '$acct' not found or failed to update: "
Write-Host $_
}
}
EDIT: Added $<Underbar> to original $acct = $samaccountname # needed for error message