Script Repository


Convert user mailbox to shared or resource mailbox in Exchange Online

April 28, 2020
18357

The script can be used in Business Rules, Custom Commands and Scheduled Tasks to convert an Microsoft 365 (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 Microsoft 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    $Context.LogMessage("The user doesn't have a Microsoft 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 ( 6 )
avatar
Karbon Homes
Oct 05, 2018
Is there a similar script for on premise please?
avatar
Support
Oct 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
Sep 25, 2019
I see this method uses Basic Authentication. Can you guys start developing Powershell scripts for Modern Authentication?
avatar
Support
Sep 26, 2019

Hello Andrew,

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

avatar
Tim
Jan 06, 2020
The Exchange Team has announced that in October 2020 they will be turning off basic authentication for all protocols including remote powershell. Does Adaxes have a plan for this?
avatar
Support
Jan 09, 2020

Hello Tim,

Before the October 2020, we will release an update that will use another authentication for communication with Exchange Online. Also, there will be patches issued for older versions.

Leave a comment