In this example, I will change Telephone Number of the user objects. When I checked the attribute name is shown as telephoneNumber but we have to use OfficePhone as the parameter on our script. Otherwise powershell gives error and tells us -telephoneNumber parameter not found.
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
Set-ADUser -Identity $User.SamAccountName -OfficePhone $User.$null
}
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
Set-ADUser -Identity $User.SamAccountName -OfficePhone $User.Phone
}
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
Set-ADUser -Identity $User.SamAccountName -OfficePhone $User.Phone -EmailAddress $User.Email -Department $User.Department -Displayname $User.DisplayName -Description $User.Description
}
And all fields are updated successfully.
We can change set-aduser command as multiline command for a better readability by using a space followed by the backtick (AltGr + ,) on Turkish keyboard.
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
Set-ADUser -Identity $User.SamAccountName `
-OfficePhone $User.Phone `
-EmailAddress $User.Email `
-Department $User.Department `
-Displayname $User.DisplayName `
-Description $User.Description
}