Use this script to modify and/or complete the hybrid migration for a single user in a O365 Mailbox migration.
The provided script performs the following tasks:
- Prompts the user to enter a username using the `Read-Host` cmdlet. The entered username is stored in the variable `$user`.
- Retrieves the current date and formats it as “MM/dd/yyyy” using the `Get-Date` cmdlet. The formatted date is stored in the variable `$day`.
- Constructs a new date and time string by concatenating the value of `$day` with the string ” 5:00 AM”. The resulting string is stored in the variable `$date`.
- Retrieves move requests for the specified user using the `Get-MoveRequest` cmdlet, with the user’s identity passed as the `-Identity` parameter.
- Displays a message instructing the user to press Enter to continue or CTRL-C to exit using the `Write-Host` cmdlet.
- Waits for the user to press a key using the `$host.UI.RawUI.ReadKey()` method. The options “NoEcho” and “IncludeKeyDown” are specified to prevent the pressed key from being displayed on the console. The read key is stored in the variable `$x`, but it is not used further in the script.
- Initiates the completion of the move request for the specified user using the `Set-MoveRequest` cmdlet. The user’s identity is passed as the `-Identity` parameter. The move request is set to complete after the date and time specified by `(Get-Date “$date”).ToUniversalTime()`. The `-BadItemLimit` parameter is set to 1000, allowing up to 1000 bad items to be skipped during the move. The `-AcceptLargeDataLoss` parameter is used to accept a potential data loss during the move. The `-Confirm` parameter is set to `$False` to skip the confirmation prompt.
Copy the script below or download the txt file.
$user = Read-Host -Prompt ‘User Name’
$day = Get-Date -Format “MM/dd/yyyy”
$date = $day + ” 5:00 AM”
#(confirm move is “synced”)
Get-MoveRequest -Identity $user
Write-Host “Press enter to continue and CTRL-C to exit …”
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)
#(complete move, change date to today)
Set-MoveRequest -Identity $user -CompleteAfter (Get-Date “$date”).ToUniversalTime() -BadItemLimit 1000 -AcceptLargeDataLoss -Confirm:$False