Exchange

用於刪除 Exchange 2010 郵件聯繫人的輔助 SMTP 地址的 Powershell 腳本

  • May 26, 2020

我有幾千個 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

關於如何解決這個問題的任何幫助?

你需要周圍的報價*@domain.local

引用自:https://serverfault.com/questions/447154