Script Repository


Get mailbox move status in Exchange Online

May 05, 2021
2048

The script gets the status of the move of a user's mailbox in Exchange Online. The status is added to the Execution Log of the operation.

Edit Remove
PowerShell
try
{
    # Get the object ID in Microsoft 365
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    return # The user doesn't have a Microsoft 365 account
}

try
{
    # Connect to Exchange Online
    $session = $Context.CloudServices.CreateExchangeOnlinePSSession()
    Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Get-MoveRequest"
    
    try
    {
        $moveRequest = Get-MoveRequest -Identity $objectId.ToString() -ErrorAction Stop
    }
    catch
    {
        return # There are no requests to move the user's mailbox
    }
    
    # Output Move request status
    $Context.LogMessage("Move request status: " + $moveRequest.Status, "Information")
}
finally
{
    # Close the remote session and release resources
    if ($session) { Remove-PSSession $session }
}


Comments ( 0 )
No results found.
Leave a comment

Related Scripts