Powershell在Exchange 2010中修改电子邮件地址
问题描述:
我试图在所有电子邮件地址之前添加文本,而不是覆盖并创建最后一个电子邮件地址的一个副本。任何想法是什么造成这种情况?Powershell在Exchange 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
}
预期输出:[email protected],[email protected]
,但它给:[email protected],[email protected]
它不是在所有的邮件添加Disabled
。
答
实际结果表明$($ 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
希望这会对您有所帮助。
我试过这个代码,它这样做同样的 –
好了,所以请检查数据类型是什么$($ address.SmtpAddress): $($ address.SmtpAddress).GetType() $($ address.SmtpAddress)| %{$ _。GetType()}把这段代码放在循环中 – ALIENQuake
类型是system.string, –