PowerTip: Set Custom Attributes in Active Directory


Summary: Use the Set-ADUser cmdet to modify custom attributes.

Hey, Scripting Guy! Question How can I use Windows PowerShell to modify a custom attribute in Active Directory?

Hey, Scripting Guy! Answer Use the Set-ADUser cmdlet and it’s –add-replace, and –remove parameters to adjust custom attributes.

For example, to update the Info attribute in Active Directory and replace it with a new value:

SET-ADUSER john.smith –replace @{info=”John Smith is a Temporary Contractor”}

Comments (11)

  1. Brad_Voris says:

    Awesome I needed this thank you!

  2. Chen V says:

    Helpful for IDM (Identity Management Team)

  3. Mark P. says:

    Excellent, very helpful!

  4. Aldu says:

    Thanks alot!

  5. Madura says:

    How can I add attribute to the Active Directory schema? if we take example new attribute called "Home Phone Number" how can I add this thing using powershell cmdlets.
    Thank You.

  6. EDGARD says:

    It was a great help. I was searching for something like this, just edited. Thank you!

  7. Aaron W says:

    I am getting an exception when I try to perform this command within a For loop or If statement. Everything seems to break with the existence of -replace. Even if I double quote the whole line, "Set-AdUser $USamaccountName –replace @{ManagerEmployeeId=$MEmpID}",
    everything breaks. Only when I remove the line or comment out the line will the script run.

  8. Aaron W says:

    Nevermind I got it. Ye olde hyphen/dash problem. I retyped the line and it worked.

  9. Mohamed says:

    Very useful. Thank you so much 🙂

  10. A.MIL says:

    Excellent. Thank you so much for this info.

  11. seleleth says:

    Note that if your custom attribute contains certain characters like a hyphen you need to enclose it within quotes:

    Set-ADUser user1 -replace @{"attribute-with-dashes"="value to set"}

    Otherwise I was getting this error (char 37 being the location of the first hyphen):

    Missing ‘=’ operator after key in hash literal.
    At line:1 char:37

Skip to main content