Powershell在Exchange 2010中修改Emailaddresses

时间:2015-07-20 10:37:13

标签: powershell exchange-server-2010

我正在尝试在所有电子邮件地址之前添加文本,而不是覆盖并创建最后一个电子邮件地址的副本。是什么原因引起了这个?

$UD = Get-Mailbox -Identity $_identity
$SmtpAdd=$UD|select -ExpandProperty EmailAddresses|Select SmtpAddress
foreach($address in $SmtpAdd)
    {
    $Changed="Disabled_"+$($address.SmtpAddress)
    Set-Mailbox $_identity -EmailAddresses $Chnged -EmailAddressPolicyEnabled $true

    }

期待输出:Disabled_rave@in.com,Disabled_raj@in.com

但它正在给予:Disabled_raj@in.com,raj@in.com.

在所有邮件中都没有添加Disabled

1 个答案:

答案 0 :(得分:0)

您的实际结果表明$($ address.SmtpAddress)是一个字符串。在这种情况下,你要梳理两个字符串:

"a" + "b,c" and the results of this operation will be "ab,c"

所以你需要通过','拆分$($ address.SmtpAddress),为每个元素添加“Disabled_”,将所有新的电子邮件地址存储在数组中,然后将这些元素作为字符串连接起来'':

[array]$Changed = $null
$($address.SmtpAddress) -split ',' | % {
    $Changed += "Disabled_"+ $_
    }
$Changed = $Changed -join ','
Set-Mailbox $_identity -EmailAddresses $Chnged -EmailAddressPolicyEnabled $true

希望这会对你有所帮助。

相关问题