Written by Super User.

Change User Attribute to Null or some value

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.csv file will be in the following format. SamAccountName is just a header. Under the header add samaccountname of the users. 
SamAccountName
selimatmaca
cevatkelle
 
Script1: This script sets the Telephone Number as Null.
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
    Set-ADUser -Identity $User.SamAccountName -OfficePhone $User.$null  
}
 
 
 
If you need to set Phone number to something else instead of a Null value. You can change users.csv and your script like this:
 
SamAccountName,Phone
selimatmaca,99999999
cevatkelle,00000000
$users = Import-CSV c:\users.csv
foreach($User in $Users)
{
    Set-ADUser -Identity $User.SamAccountName -OfficePhone $User.Phone  
}
 
 
If you need to change multiple attributes. Change users.csv and the script like this:
 
SamAccountName,Phone,Email,Department,DisplayName,Description
selimatmaca,99999999,This email address is being protected from spambots. You need JavaScript enabled to view it.,IT,"Yavuz Selim Atmaca","Some Description"
cevatkelle,00000000,This email address is being protected from spambots. You need JavaScript enabled to view it.,HR,"Cevat Kelle","Some Description"
$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
}