Set Any Attribute of AD users by using PowerShell Script

Updated Post: Now, instead of the SamAccountName you need to use Identity in the csv header to identify users (which is the existing SamAccountName of users).

Eg: if you want to modify the user who has the SamAccountName user01 to user001, then you need to put user01 under the Identity column and user001 under SamAccountName column in the csv file.

Hello fellow scripters, I’d like to share the script that I have been working on for a few days. With this script, you can set any AD attribute of users from a csv text file. There are 3 parameters that you need to specify.

-File Path : Path of the csv file which contains the AD user attributes. This parameter is mandatory.

-OverwriteEmptyAttrib : This will determine whether the empty attributes found in the csv file will overwrite to existing AD users’ attribute or not. This parameter accepts $True or $False and it becomes mandatory if there are empty attributes defined in the csv file.

-RenameCN : This will rename the CN (Common Name) of the user if specified. This parameter is optional.


  • You can include as many attributes as you can see in the attributes tab of the user. See Fig-3.
  • Make sure you installed RSAT tool if you’re going to run the script on Windows Desktops. For Windows servers, you can install it by running the powershell command Install-WindowsFeature -Name “RSAT-AD-PowerShell”
  • As this script is to modify the existing user attributes, SamAccountName is a mandatory value that you need to define in the csv file.
  • For the manger attribute, you don’t need to specify the distinguished name of the manger but instead you can just put the SamAccountName of the manager.
  • For the multi-value attributes (eg: postOfficeBox, proxyAddresses) , you need to write the values in @(‘value1′,’value2′,’value3’) which means an array in powershell. See Fig-2 for details.

You can find the script from the gist or at the end of this page.

Fig-1: Demo Run
Fig-2: Sample CSV file with user attributes
Fig-3: You can use any of these attribute name in the csv file

You can download my script here.

2 thoughts on “Set Any Attribute of AD users by using PowerShell Script”

  1. hey buddy,

    This script Work yet?

    I get this error: FilePath: C:\temp\AD_Users_Attributes.csv
    The csv headers must contain ‘Identity’ which is the SamAccountName of users. Script exits.

    1. You need to put a column ‘Identity’ in the csv file which contains the current SamAccountName of users. Please just note to test with a few users first.

Leave a Reply

Your email address will not be published. Required fields are marked *