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

时间:2019-05-01 08:24:45

标签: powershell office365 exchange-server-2010

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

以下错误在尝试转换时显示。 无法处理参数“类型”上的参数转换。无法将值“ Shared”转换为类型“ Microsoft.Exchange.Management.RecipientTasks.ConvertibleRemoteMailboxSubType”,原因是 无效的枚举值。指定以下枚举值之一,然后重试。可能的枚举值为“常规,房间,设备”。

我们正在运行Exchange 2010 hybird。

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
    }

}

1 个答案:

答案 0 :(得分:0)

请注意Microsoft对共享类型的评论:

关于“共享价值”的注释:

  

共享仅在Exchange 2013 CU21或更高版本和Exchange中可用   2016 CU10或更高版本。要使用此值,还需要运行setup.exe   / PrepareAD。有关更多信息,请参见KB4133605。

     

您只能在最初在以下位置创建的邮箱上使用“共享”   在线交流。如果邮箱最初是在本地创建的   Exchange,然后迁移到Exchange Online,则需要迁移   邮箱返回到本地Exchange,将邮箱转换为共享   本地Exchange中的邮箱,然后迁移共享邮箱   交流在线。或者,您可以更改RemoteRecipientType   本地邮箱的属性值设置为“ ProvisionMailbox,   迁移,DeprovisionArchive”,方法是在   Exchange服务器:Set-ADUser -Identity“”-替换   @ {msExchRemoteRecipientTYpe =“ 21”}。

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