Naigel
Naigel

Reputation: 9644

Adding and removing extensionattribute to AD object

I'm using powershell to modify some AD extensionattribute.

This is my code to add an extensionattribute

Set-ADUser -Identity "anyUser" -Add @{extensionAttribute4="myString"}

It works, but how can I remove the same extensionattribute? I can't find anything similar to -remove.

Upvotes: 19

Views: 281141

Answers (7)

Metin Özdemir
Metin Özdemir

Reputation: 11

Set-ADUser -Identity anyUser -Replace @{extensionAttribute4="myString"}

This is also usefull

Upvotes: 1

Jim Henderson
Jim Henderson

Reputation: 141

I used the following today - It works!

Add a value to an extensionAttribute

 $ThisUser = Get-ADUser -Identity $User -Properties extensionAttribute1
    Set-ADUser –Identity $ThisUser -add @{"extensionattribute1"="MyString"}

Remove a value from an extensionAttribute

  $ThisUser = Get-ADUser -Identity $User -Properties extensionAttribute1
  Set-ADUser –Identity $ThisUser -Clear "extensionattribute1" 

Upvotes: 14

Christoph Bock
Christoph Bock

Reputation: 31

I have struggled a long time to modify the extension attributes in our domain. Then I wrote a powershell script and created an editor with a GUI to set and remove extAttributes from an account.

If you like, you can take a look at it at http://toolbocks.de/viewtopic.php?f=3&t=4

I'm sorry, that the description in the text is in German. The GUI itself is in English.

I use this script on a regular basis in our domain and it never deleted anything or did any other harm. I provide no guarantee, that this script works as expected in your domain. But as I provide the source, you can (and should) have a look at it, before you run it.

Upvotes: 3

Zage
Zage

Reputation: 1

To clear the value you can always reset it to $Null. For example:

Set-Mailbox -Identity "username" -CustomAttribute1 $Null

Upvotes: 0

Shay Levy
Shay Levy

Reputation: 126762

Or the -Remove parameter

Set-ADUser -Identity anyUser -Remove @{extensionAttribute4="myString"}

Upvotes: 0

Richard
Richard

Reputation: 7000

You could try using the -Clear parameter

Example:-Clear Attribute1LDAPDisplayName, Attribute2LDAPDisplayName

http://technet.microsoft.com/en-us/library/ee617215.aspx

Upvotes: 15

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

Extension attributes are added by Exchange. According to this Technet article something like this should work:

Set-Mailbox -Identity "anyUser" -ExtensionCustomAttribute4 @{Remove="myString"}

Upvotes: 1

Related Questions