需要删除emailattribute AD / powershell中的值

时间:2014-05-15 14:36:25

标签: powershell

您好我需要在用户上将emailattribute设置为null / nothing。我创造了这个:

   
Get-ADGroupMember -Identity "testgrupp" | Get-ADUser -Properties samaccountname | Foreach {
Set-ADUser -Identity $_ -EmailAddress ("")
}

但它失败了,我认为它的最后一部分是错的?

2 个答案:

答案 0 :(得分:1)

解决此问题的几种方法:

使用Select-Object的-ExpandProperty参数,以便只获取samaccountname字符串:

Get-ADGroupMember -Identity "testgrupp" |
 Get-ADUser -Properties samaccountname | 
 Select -ExpandProperty samaccountname |
 Foreach {
          Set-ADUser -Identity $_ -EmailAddress ("")
        }

或引用Set-ADUser中的samaccountname属性:

Get-ADGroupMember -Identity "testgrupp" | 
Get-ADUser -Properties samaccountname | 
Foreach {
         Set-ADUser -Identity $_.samaccountname -EmailAddress ("")
        }

答案 1 :(得分:1)

("")替换为$null

   
Get-ADGroupMember -Identity "testgrupp" | 
Get-ADUser -Properties samaccountname | Foreach {
    Set-ADUser -Identity $_ -EmailAddress $null
}