Script Repository


Convert user mailbox to shared or resource mailbox in Exchange Online

July 16, 2019
7772

The script can be used in Business Rules, Custom Command and Scheduled Tasks to convert an Office 365 user mailbox to a room, equipment or shared mailbox. To add it to your rule, command or task, use the Run a program or PowerShell script action.

Note: For information on how to create resource mailboxes in Exchange On-Premises, see Provision shared and room mailboxes.

Parameter:

  • $mailboxType - specifies the type of mailbox you want to get.
Edit Remove
PowerShell
$mailboxType = "Shared" # TODO: uncomment the type you need
# $mailboxType = "Room"
# $mailboxType = "Equipment"

# Get the object ID in Office 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    $Context.LogMessage("The user doesn't have an Office 365 account", "Warning")
    return
}

try
{
    # Connect to Exchange Online
    $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $Context.GetOffice365Credential() -Authentication Basic -AllowRedirection
    Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Set-Mailbox"
    
    # Change mailbox type
    Set-Mailbox $objectId.ToString() -Type $mailboxType
}
catch
{
    $Context.LogMessage($_.Exception.Message, "Warning")
}
finally
{
    # Close the remote session and release resources
    Remove-PSSession $session
}

Comments ( 1 )
avatar
Karbon Homes
October 05, 2018

Is there a similar script for on premise please?

avatar
Support
October 05, 2018

Have a look at the script in the Exchange On-Premises section of the following article in our repository: https://www.adaxes.com/script-repository/connect-to-exchange-with-powershell-s506.htm.

Leave a comment