How to update AD user attributes using Set-ADUser

Last updated on:

The Set-ADUser PowerShell cmdlet lets administrators quickly update user account attributes like passwords, managers, or settings without using the UI. It helps maintain accurate data, apply organizational policy changes, and perform bulk updates efficiently. This article includes steps and practical examples to help you manage users while ensuring security and compliance.

  • PowerShell
  • ADUC
  • ADManager Plus
  • Native tools limitations
  • Why ADManager Plus
  • FAQs
 

Steps to update AD user attributes using PowerShell

  1. Open PowerShell ISE as an administrator.
  2. If the AD module isn't installed, download and install the RSAT package for your Windows version. Then import the module.
    Import-Module ActiveDirectory
  3. Run the following command to update a specific attribute for a user. Replace username with the user's login name and attributeName and newValue with the property you want to modify.
    Set-ADUser -Identity "username" -Replace @{attributeName="newValue"}

Supported parameters

The following are a few commonly used parameters with the Set-ADUser cmdlet:

Parameter Description
-Identity Specifies the user account to modify. You can use the user's SAM account name, distinguished name (DN), GUID, or UPN.
-Replace Updates one or more existing attribute values. Useful for changing properties like Title, Department, or ProxyAddresses.
-Add Adds new values to multi-valued attributes such as ProxyAddresses or extension attributes without removing existing ones.
-Manager Sets or updates the manager attribute for a user.
-AccountExpirationDate Sets or modifies the date when the user account will expire.
-ChangePasswordAtLogon Forces the user to change their password at the next sign-in.
-Credential Runs the command using alternate credentials.
-Server Specifies the domain controller or AD DS instance to connect to.
-PassThru Returns the modified user object for verification or further use in scripts.

Examples using Set-ADUser

Example 1: Update AD user's password and force them to change it at the next logon.

Resets user's password and set the account option to user must change password at next logon

Set-ADUser -Identity <sAMAccountName> -ChangePasswordAtLogon $true
Set-ADAccountPassword -Identity <sAMAccountName> -NewPassword (ConvertTo-SecureString "NewP@ssw0rd!" -AsPlainText -Force)

Example 2: Update AD user's manager

Assigns or changes the manager for a user.

Set-ADUser -Identity <sAMAccountName> -Manager "cn=<managerCN>,ou=<OUName>,dc=<domain>,dc=<tld>"

Example 3: Replace existing attribute values

Uses the -Replace parameter to update one or more attributes like Title and Department at once.

Set-ADUser -Identity <sAMAccountName> -Replace @{Title="<JobTitle>"; Department="<DepartmentName>"}

Example 4: Update AD user's proxy addresses

Adds or replaces proxy email addresses for a user using Set-ADUser.

Set-ADUser -Identity <sAMAccountName> -Add @{ProxyAddresses="SMTP:<PrimaryEmail>","smtp:<SecondaryEmail>"}

To replace all proxy addresses:

Set-ADUser -Identity <sAMAccountName> -Replace @{ProxyAddresses="SMTP:<PrimaryEmail>"}

Example 5: Set extension attributes

Adds or modifies custom extension attributes.

Set-ADUser -Identity <sAMAccountName> -Add @{extensionAttribute1="<Value1>"; extensionAttribute2="<Value2>"}

Example 6: Update multiple account options

Changes common account settings like office, description, and expiration date.

Set-ADUser -Identity <sAMAccountName> -Office "<OfficeLocation>" -Description "<DescriptionText>" -AccountExpirationDate "<MM/DD/YYYY>"

Example 7: Disable AD user's account

Disables user's account that's no longer active or needs to be temporarily blocked.

Set-ADUser -Identity <sAMAccountName> -Enabled $false

Example 8: Modify AD account control values

Changes common account settings like password options, account lockout, or expiration.

Set-ADUser -Identity <sAMAccountName> -ChangePasswordAtLogon $true

Example 9: Unlock an AD user's account

Unlocks user's account that's been locked out due to failed logon attempts.

Unlock-ADAccount -Identity <sAMAccountName>

Example 10: Modify AD object attributes

Changes common account settings like office, description, and expiration date.

Set-ADUser -Identity <sAMAccountName> -Title "<JobTitle>" -Department "<DepartmentName>"

Troubleshooting tips

Error: Cannot validate argument on parameter 'Identity'. The argument is null.

Solution: This happens when the value passed to -Identity isn't valid. Make sure your CSV or input variable contains the correct attribute such as SamAccountName or DistinguishedName. If you're using a script, confirm you're referencing the right column, for example, use $_.SamAccountName instead of $_.userPrincipalName if that's what your data provides.

Error: A parameter cannot be found that matches parameter name 'physicalDeliveryOfficeName'.

Solution: This means you used an attribute that isn't a direct parameter of the cmdlet. Double-check the attribute name and supported parameters for Set-ADUser in Microsoft Docs. For extended attributes, use the hash table format instead. For example:

-Replace @{physicalDeliveryOfficeName='Value'} instead of calling it directly.

Error: The parameter is incorrect (when modifying custom properties).

Solution: This usually happens when the data type doesn't match what the attribute expects. For instance, use $True or $False for Boolean properties instead of "1" or "0". For custom attributes, check their type first and make sure you're using the correct format, don't wrap Booleans or numbers in quotes.

Error: Set-ADUser: Multiple values were specified for a single-valued property.

Solution: You're trying to add more than one value to a property that only accepts one. Attributes like description or notes are single-valued. If you need to append information, join the old and new text together manually and use -Replace with the complete combined string.

Error: Unable to contact the server. This may be because this server does not exist, it is currently down, or it does not have the Active Directory Web Services running.

Solution: The script can't connect to a domain controller. Check network connectivity, DNS resolution, and ensure Active Directory Web Services is running. If needed, try another domain controller or verify replication health using dcdiag or repadmin commands.

Error: Access is denied.

Solution: The account running the script lacks sufficient permissions to modify AD user attributes. Run PowerShell with a user account that has appropriate write permissions in AD, such as an account in the Account Operators or Domain Admins group.

Error: Error parsing query or invalid filter expression.

Solution: This error often results from syntax issues in the -Filter or property parameters. Ensure all attribute names are correct, string values are enclosed in single quotes, and special characters are escaped properly.

Update AD user attributes using ADUC

AD Users and Computers (ADUC) is a common method to update user attributes.

  1. Open ADUC.
  2. Click View > Advanced Features to enable the Attribute Editor tab.
  3. Browse the OUs to find the user account you want to edit.
  4. Right-click the user and select Properties.
  5. Click the Attribute Editor tab.
  6. Click the attribute you want to change.
  7. Type the new value under Value to add and click OK.
  8. Click Add to add multiple values.
  9. Click Apply.
  10. Click OK to close the properties window.
Updating user attributes in AD using ADUC.

Update AD user attributes using ADManager Plus

  1. Log in to ADManager Plus and navigate to Management > User Management.
  2. Under Bulk User Modification, select the required attribute.
  3. Select your domain, enter the user's name, and click OK. To add multiple users in bulk, click the CSV Import and upload a CSV file containing the user list.
  4. Click Search.
Updating user attributes in AD using ADManager Plus.

ADManager Plus streamlines the entire process, eliminating errors and providing a simple solution for all AD user management actions.

Limitations of using native tools to update AD user attributes

Relying only on PowerShell and ADUC to update AD user attributes has some drawbacks:

  • PowerShell scripts can become complex when updating multiple attributes.
  • Troubleshooting errors takes time and affects productivity.
  • Delegation is hard since updates often need admin rights.
  • ADUC supports only one user at a time with no bulk update option.
  • ADUC also lacks automation and customization for recurring tasks.

Highlights of using ADManager Plus to update AD user attributes

ADManager Plus makes AD management easier and faster through a single, intuitive console. Here’s why it’s a better choice for IT teams:

FAQs

The Set-ADUser and Enable-ADAccount cmdlets can be used to enable an AD user. Run the command below by replacing username with the actual user logon name, distinguished name, or object GUID.

Enable-ADAccount -Identity username
Set-ADUser -Identity username -Enabled $true

Alternatively, script-free tools like ManageEngine ADManager Plus can be used to enable an AD user with just a few clicks.

  1. Sign in to ADManager Plus.
  2. Navigate to Management > User Management.
  3. Click Enable/Disable Users under Bulk User Modification.
  4. Click Enable and select the desired domain and the names of user accounts to be enabled. You can even import the users list from a CSV file. Click Apply.

Custom attributes (including extension or schema attributes) can be updated directly using Set-ADUser by replacing extensionAttribute1 with any schema attribute available in your AD setup and YourValue with the desired value.

Set-ADUser -Identity username -Replace @{extensionAttribute1="YourValue"}

Alternatively, tools like ManageEngine ADManager Plus let you perform the same task easily without using scripts.

  1. Sign in to ADManager Plus.
  2. Navigate to Management > User Management.
  3. Click Custom Attributes under Bulk User Modification.
  4. Enter the required details like LDAP Name, Data Type, and Value.
  5. Find the users either by searching manually or by importing a CSV file, then click Search .
  6. Use the check boxes to select the users you want to modify.
  7. Click Apply to update the custom attribute values.

Simplify AD bulk management and reporting with ADManager Plus

The one-stop solution to Active Directory Management and Reporting
Email Download Link