We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Get mailbox move status in Exchange Online

May 05, 2021 Views: 3084

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers