![Powershell 脚本用于删除 Exchange 2010 邮件联系人的辅助 SMTP 地址](https://linux22.com/image/600286/Powershell%20%E8%84%9A%E6%9C%AC%E7%94%A8%E4%BA%8E%E5%88%A0%E9%99%A4%20Exchange%202010%20%E9%82%AE%E4%BB%B6%E8%81%94%E7%B3%BB%E4%BA%BA%E7%9A%84%E8%BE%85%E5%8A%A9%20SMTP%20%E5%9C%B0%E5%9D%80.png)
我有几千个 Exchange 2010 邮件联系人,他们被默认收件人策略错误地分配了内部 SMTP 地址。
我正在尝试使用以下命令删除这些地址(保留主 SMTP)并禁用收件人策略的自动更新,以便 SMTP 地址不会再次重新创建。
Get-MailContact -OrganizationalUnit "domain.local/OU" -Filter {EmailAddresses -like *@domain.local -and name -notlike "ExchangeUM*"} -ResultSize unlimited -IgnoreDefaultScope | foreach {
$contact = $_
$email = $contact.emailaddresses
$email | foreach {
if ($_.smtpaddress -like *@domain.local) {
$address = $_.smtpaddress
write-host "Removing address" $address "from Contact" $contact.name
Set-Mailcontact -Identity $contact.identity -EmailAddresses @{Remove=$address}
$contact | set-mailcontact -emailaddresspolicyenabled $false
}
}
}
但是我收到了以下错误:
You must provide a value expression on the right-hand side of the '-like' operator.
At line:1 char:312
+ Get-MailContact -OrganizationalUnit "domain.local/testou" -Filter {EmailAddresses -like "*@domain.local" -and name -notlike "ExchangeUM*"} -ResultSize unlimited -IgnoreDefaultScope | foreach {$contact = $_; $
email = $contact.emailaddresses; $email | foreach {if ($_.smtpaddress -like <<<< *@domain.local) {$address = $_.smt
paddress; write-host "Removing address" $address "from Contact" $contact.name; Set-Mailcontact -Identity $contact.ident
ity -EmailAddresses @{Remove=$address}; $contact }}
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedValueExpression
关于如何修复此问题有什么帮助吗?
答案1
你需要引用*@domain.local