I'm trying to write a script to created a remote shared mailbox but its not working.
following error show when try to convert it. Cannot process argument transformation on parameter 'Type'. Cannot convert value "Shared" to type "Microsoft.Exchange.Management.RecipientTasks.ConvertibleRemoteMailboxSubType" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Regular, Room, Equipment".
We are running 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 "[email protected]" `
-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
}
}