2013-04-04 239 views
9

我正在使用powershell來修改某些AD擴展屬性。添加和刪除擴展屬性到AD對象

這是我的代碼添加一個extensionattribute

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

它的工作原理,但我怎麼能去掉相同extensionattribute?我找不到類似於-remove的任何內容。

回答

1

擴展屬性由Exchange添加。據this Technet article這樣的事情應該工作:

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

還是-Remove參數

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

要清除該值,您始終可以將其重置爲$ Null。例如:

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

2

我已經掙扎了很長一段時間來修改我們的領域的擴展屬性。 然後我寫了一個powershell腳本,並創建了一個帶有GUI的編輯器來設置和刪除帳戶中的extAttributes。

如果你願意,你可以在http://toolbocks.de/viewtopic.php?f=3&t=4

看看它,我很抱歉,在文本描述是在德國。 GUI本身是英文的。

我在我們的域中定期使用這個腳本,它從不刪除任何東西或做任何其他傷害。我無法保證,此腳本在您的域中按預期工作。但是當我提供源代碼時,您可以(也應該)在運行之前查看它。

7

我今天用了以下 - 它的作品!

的值添加到一個extensionAttribute

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

從extensionAttribute刪除值

$ThisUser = Get-ADUser -Identity $User -Properties extensionAttribute1 
    Set-ADUser –Identity $ThisUser -Clear "extensionattribute1" 
0
Set-ADUser -Identity anyUser -Replace @{extensionAttribute4="myString"} 

這也有用