Add Clear and Replace in Active directory with PowerShell

A lot of the common account attributes can be set with the syntax:

Set-ADUser -attributename <value>

However there are a lot of attributes in Active Directory that are not in one of the parameter sets. For these settings you need to use Add to add a new value, Clear to remove any value set and replace to replace to swap the current value with a new one.

In the first example the account cuser has the extensionAttribute4 set to A

Set-ADUser -Identity CUser -Add @{extensionAttribute4=”A”}

In the next example this attribute is set from A to B

Set-ADUser -Identity cuser -replace {extensionAttribute4=”A”;extensionAttribute4=”B”}

In the final example there is no value set for this attribute. It is now blank.

Set-ADUser -Identity cuser -clear extensionAttribute4