无法使用PowerShell从地址列表中隐藏电子邮件

时间:2017-04-10 13:31:04

标签: powershell email error-handling outlook

我正在尝试使用PowerShell运行一个简单的命令来隐藏地址列表中的电子邮件帐户。到目前为止,这是我的代码。

cls

$EmployeeEmail = "user@example.com"

#Need to hide the Mailbox from address list
$MethodName = "Hide Email Account"

$username = "staff"
$password = "accounts"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchmbca1.example.local/PowerShell/ -Authentication Kerberos -Credential $cred

Import-PSSession $Session

Set-Mailbox -Identity $EmployeeEmail -HiddenFromAddressListsEnabled $true

Remove-PSSession $Session

但是,当我运行此命令时,收到以下错误消息:

无法执行此操作,因为对象' user@example.com'无法在' servername.example'。

上找到

我尝试使用' DOMAIN \ username'更改我传递给Set-Mailbox cmdlet的-Identity的值。我也收到同样的错误。我知道该帐户存在,因为我可以使用Get-ADUser进行搜索并找到具有SAMAccountName的帐户。任何帮助将非常感激。谢谢!

0 个答案:

没有答案