Sorry for the delay in the reply. Here is the rule and the associated errors. I am trying to check for users that were create on prem and have finally synced to O365 then migrate the mailbox to office 365 for the user.
Capture of the Rule
Script Migrate Mailbox to Office 365
Import-Module MsOnline
Try
{
Connect-MsolService -Credential $Context.GetOffice365Credential()
}
Catch
{
$Context.LogMessage("Unable to connect to Office 365", "Error")
return
}
# Find a corresponding account in Office 365
#$userPrincipalName = %userPrincipalName%
$Context.LogMessage("Looking for Account - %userPrincipalName%", "Information")
$found = $false
While($found -eq $False)
{
Try
{
$user = Get-MsolUser -UserPrincipalName %userPrincipalName% -ErrorAction SilentlyContinue
}
Catch
{
}
If($user -ne $null)
{
$Context.LogMessage("User account for %userPrincipalName% found in Office 365, attempting to move mailbox to Office 365", "Information")
$office365DeliveryDomain = "<Delivery domain" # TODO: modify me
# 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
# Credentials of the local Exchange domain administrator
$localAdminName = <Serviceaccount>
$localAdminPassword = ConvertTo-SecureString -AsPlainText -Force -String <Password>
$localAdminCredentials = New-Object -TypeName System.Management.Automation.PSCredential($localAdminName, $localAdminPassword)
try
{
$result = New-MoveRequest -Identity %username% -BatchName %username% -Remote -RemoteHostName "Remote host domain" -TargetDeliveryDomain $office365DeliveryDomain -RemoteCredential $localAdminCredentials -ErrorAction Stop
}
catch
{
$Context.LogMessage("Unable to create Move Request for %username%", "Error")
$Context.LogMessage($_.Exception.Message, "Error")
}
if ($result -ne $NULL)
{
$Context.LogMessage("Mailbox move request created successfully. Check Exchange logs for details." , "Information")
}
Remove-PSSession $Session
return # exit script
$found = $true
}
Else
{
$Context.LogMessage("User has not synced with Office 365 yet, sleeping 10 minutes and checking again." , "Information")
Start-Sleep -Seconds 600
}
}
User in AD has the extensionattribute3 set
Script reports nothing in the activity log
Error in event log from the adaxes service looking for the user online
O365 search for the same user finds the user without issue. (sorry couldn't add another screen shot.