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
}
# Connect to Exchange Online
$Context.CloudServices.ConnectExchangeOnline()
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")