Forum Discussion
LED04
Oct 13, 2021Copper Contributor
"NeedsApproval"
Hi All, So I have been migrating mailboxes from onprem to O365 in the hybrid config with no issues. Today I have two migration batch jobs that state "NeedsApproval", but everything migrated. Kind ...
Waldis007
Mar 18, 2024Copper Contributor
I realize I'm responding three years later, but I'm engaged in the same battle against a familiar adversary. I've crafted a script that searches for users requiring approval. Upon identifying one or more such users, it proceeds to approve all found. Conversely, if no users are found needing approval, the script waits for 30 seconds before conducting another search. This loop—checking, waiting if necessary, and then acting on any findings—continues, ensuring that the script runs actively for an hour with real-time feedback. Both the frequency of checks and the script's overall runtime are customizable. This approach could prove beneficial for anyone grappling with this persistent challenge.
# Save the start time
$startTime = Get-Date
# Define the duration to run the script (60 minutes)
$duration = New-TimeSpan -Minutes 60
# Initialize a counter for the loop iterations
$iteration = 0
# Run the loop until the current time is less than start time + duration
while ((Get-Date) -lt $startTime.Add($duration)) {
# Increase the counter
$iteration += 1
try {
# Attempt to get migration users with status 'needsapproval'
$users = Get-MigrationUser -Status needsapproval -ErrorAction Stop
# Check if there are any users needing approval
if ($users -and $users.Count -gt 0) {
# Approve skipped items for users with status 'needsapproval'
$users | Set-MigrationUser -ApproveSkippedItems -ErrorAction Stop
# Report the number of users who were in 'needsapproval' status and processed
Write-Host "Iteration ${iteration}: Approved skipped items for $($users.Count) users at $(Get-Date)."
} else {
# Report that no users are currently in the 'needsapproval' status
Write-Host "Iteration ${iteration}: No users in 'needsapproval' status at $(Get-Date)."
}
} catch {
Write-Host "An error occurred during iteration ${iteration}: $_. The script will continue to the next iteration."
}
# Wait 30 seconds before the next iteration
Start-Sleep -Seconds 30
}
Write-Host "Script completed."