【发布时间】:2020-10-20 02:55:06
【问题描述】:
我在尝试向 Exchange 服务器上的用户别名添加新域时遇到了问题。我跑了:
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://ps.outlook.com/powershell/” -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
$Mailboxes = Get-Mailbox
Foreach ($Mailbox in $Mailboxes) {$NewAddress = $Mailbox.Alias + "@newdomain.com" $Mailbox.EmailAddresses += $NewAddress Set-Mailbox -Identity $Mailbox.Alias -EmailAddresses $Mailbox.EmailAddresses}
运行第 4 行后,我遇到:
$Mailbox.EmailAddresses += $NewAddress Set-Mailbox -Identity $Mai ...
+ ~~~~~~~~
Unexpected token '$Mailbox' in expression or statement.
还有:
At line:1 char:128
+ ... += $NewAddress Set-Mailbox -Identity $Mailbox.Alias -EmailAddresses $Mailbox.Ema ...
+ ~~~~~~~~~~~
Unexpected token 'Set-Mailbox' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
我似乎无法弄清楚为什么 $Mailbox 和 Set-Mailbox 在这种情况下不起作用。这是我第一次通过 PowerShell 尝试这样的事情,所以我有点迷茫。
任何见解都会很棒。 谢谢!
【问题讨论】:
标签: powershell email exchange-server