【问题标题】:Removing OnPremise Shared Mailbox删除本地共享邮箱
【发布时间】:2021-04-29 06:41:24
【问题描述】:

以下是我尝试执行以删除共享邮箱的脚本。我们有 on-prem 和 oncloud 共享邮箱ex,下面的脚本适用于 oncloud 共享邮箱,但它不适用于 on-prem,即使它显示成功执行。

我应该使用 Remove-ADUser 而不是 Remove-RemoteMailbox?

Try{
$SharedMailboxUPN = $payload.sharedMailboxUPN
$isOnPrem = ""
#Connect to Exchange-Online
Try
{ #FIND OUT If Shared Mailbox is On-Prem or OnCloud
$isOnPrem = Get-Mailbox -Identity $SharedMailboxUPN | Select-Object -ExpandProperty RemoteRecipientType
}
Catch
{
    #ERROR MESSAGE GOES HERE
}
if($isOnPrem -eq "Migrated, SharedMailbox") #OnPrem Mailbox
{
$sessionCheck = Get-PSSession
##### Connect to Exchange On-Prem Powershell #####
    if ($sessionCheck -eq $null)
    {
        $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$TargetServer/PowerShell/ -Authentication Kerberos -Credential $cred
        Import-PSSession $Session
    }
}
Try 
{
Remove-RemoteMailbox -Identity $SharedMailboxUPN -Confirm:$false -ErrorAction Stop #Shows result as Success, but mailbox is not removed for some reason

Remove-ADUser -Identity $SharedMailboxUPN #SHOULD I USE this instead??

}
Catch 
{
     #ERROR MESSAGE GOES HERE
}
}
else #oncloud mailbox
{
Try
{
     #Connect to ExchangeOnline
    Remove-Mailbox -Identity $SharedMailboxUPN -Confirm:$false -ErrorAction Stop
   
}
Catch
{
     #ERROR MESSAGE GOES HERE
}
}    
}
}
Catch
{
 #ERROR MESSAGE GOES HERE
}

【问题讨论】:

    标签: powershell active-directory exchange-server


    【解决方案1】:

    Remove-RemoteMailbox 仅适用于您的云共享邮箱,您可能希望 Remove-Mailbox 删除 prem 共享邮箱。使用 Remove-ADUser 将删除对象,但您应该真正使用 Exchange cmdlet 来执行此操作,否则最终可能会出现意外结果,例如孤立邮箱等

    【讨论】:

    • 所以乔纳森,Remove-RemoteMailbox 的文档说它应该只适用于本地对象,这就是我将它用于本地的原因。
    • @SumitPandey 不完全是,上面写着This cmdlet is available only in on-premises Exchange. Use the Remove-RemoteMailbox cmdlet to remove a mail-enabled user in the on-premises Active Directory and the associated mailbox in the cloud-based service.
    • @notjustme 抱歉,如果我弄错了,那么您建议我应该能够将Remove-Mailbox 用于本地和云端,它应该可以工作吗?
    • 不,帮助描述了混合方案。
    • 您需要将Remove-RemoteMailbox 用于云共享邮箱,Remove-Mailbox 用于本地共享邮箱。我在我们的混合环境中使用两者
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多