在 Office 365 中创建新的共享邮箱

Create new Shared Mailbox in Office 365

我正在尝试编写一个脚本来创建远程共享邮箱,但它不起作用。

尝试转换时出现以下错误。 无法处理参数 'Type' 的参数转换。由于无法将值 "Shared" 转换为类型 "Microsoft.Exchange.Management.RecipientTasks.ConvertibleRemoteMailboxSubType" 无效的枚举值。指定以下枚举值之一,然后重试。可能的枚举值为 "Regular, Room, Equipment".

我们是 运行 Exchange 2010 混合体。

Connect-Hybrid

$SharedMailboxOU= "Shared Mailbox OU"
$SharedMailboxAccountOU = "Shared Mailbox Account OU"

$DisplayName=$mailboxName = Read-Host "Enter Mailbox Name"

$Alias = $mailboxName.replace(" ","_")
$GroupName = ("SM_" + $Alias)

$has_mailbox_found = Get-User $mailboxName -ErrorAction SilentlyContinue

if($has_mailbox_found){
    Write-Host "Account already existed"
    exit;
}else{

    $group = New-DistributionGroup -Type Security -OrganizationalUnit $SharedMailboxOU -Name $GroupName
    if($group) { Set-DistributionGroup $GroupName -HiddenFromAddressListsEnabled $true }

    #$mailbox = New-RemoteMailbox -Name $DisplayName -Alias $Alias -OnPremisesOrganizationalUnit $SharedMailboxAccountOU

    $password = ConvertTo-SecureString -String ("Password@@HHHSHSHSS") -AsPlainText -Force  

    $mailbox =New-RemoteMailbox -UserPrincipalName "$Alias@domain-co.uk" `
        -DisplayName $Alias `
        -Name $Alias 
        -OnPremisesOrganizationalUnit $SharedMailboxAccountOU `
        -Alias $Alias `
        -Password $password

    if($group -and $mailbox) {
        Add-MailboxPermission -Identity $Alias `
                    -User $GroupName -AccessRights FullAccess -InheritanceType All

        Set-RemoteMailbox -Identity $Alias -Type Shared

        $User_Identity = $mailbox.DistinguishedName
        $User_Identity
        #Move-ADObject -Identity $User_Identity -TargetPath $SharedMailboxAccountOU
    }

}

注意微软对共享类型的评论:

关于共享值的说明:

Shared is available only in Exchange 2013 CU21 or later and Exchange 2016 CU10 or later. To use this value, you also need to run setup.exe /PrepareAD. For more information, see KB4133605.

You can only use Shared on a mailbox that was originally created in Exchange Online. If the mailbox was originally created in on-premises Exchange and then migrated to Exchange Online, you need to migrate the mailbox back to on-premises Exchange, convert the mailbox to a shared mailbox in on-premises Exchange, and then migrate the shared mailbox to Exchange Online. Or, you can change the RemoteRecipientType property value of the on-premises mailbox to "ProvisionMailbox, Migrated, DeprovisionArchive" by running the following command on an Exchange server: Set-ADUser -Identity "" -Replace @{msExchRemoteRecipientTYpe="21"}.

来源:https://docs.microsoft.com/en-us/powershell/module/exchange/federation-and-hybrid/set-remotemailbox?view=exchange-ps