Powershell 脚本用于删除 Exchange 2010 邮件联系人的辅助 SMTP 地址

Powershell 脚本用于删除 Exchange 2010 邮件联系人的辅助 SMTP 地址

我有几千个 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

相关内容