Script Repository


Convert user mailbox to shared or resource mailbox in Exchange Online

September 26, 2019
10182

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.

IMPORTANT: The script can be used for cloud mailboxes only, not for remote mailboxes.
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 ( 4 )
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.

avatar
Andrew
September 25, 2019

I see this method uses Basic Authentication. Can you guys start developing Powershell scripts for Modern Authentication?

avatar
Support
September 26, 2019

Hello Andrew,

Unfortunately, there is no such possibility as Modern Authentication requires user interaction. 

Leave a comment