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.
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 }
}