Office 365 move requests - random incremental sync interval

EMS:

There are two random number generation processes here. Firstly, a random number to change the sort order of the move requests (this is because with large numbers of move requests, the remote Exchange online PS connection can get terminated before the script completes - so the list order is changed each time the script is executed). Secondly, the time periods within the ranges specified are randomized, but only to minutes, not seconds).

The reason for the script? Because as move requests tend to be started in batches / migration batches, they generally start at the same time and there is more than a distinct possibility that they will achieve 95% sync status at the same time. As they are configured by default to 1 day, that may result in a large number of requests all wanting to do their incremental sync at the same time (possibly during business hours), which is not a good thing. Setting them to 12-24 hours in the first instance is a suggestion. Changing that to 1-3 hours in the run up to cutover is another suggestion (as the mailboxes are more likely to be synced at cutover time then).

The script checks for an Exchange online connection, although I advise closing any existing session and starting a new one each time.

[string]$ExchOnline = "outlook.office365.com"
If((Get-PsSession).Computername -ne $ExchOnline){Write-host -foregroundcolor yellow "The script requires a PsSession to $ExchOnline"; Exit}

Write-Progress -Activity "Getting the move requests" -Status "Working..."

$mrs = Get-moverequest -resultsize unlimited

[int]$rnd = get-random -Minimum 1 -Maximum 15

switch ($rnd)
    {
1 {$mrs = $mrs | sort RunspaceId}
2 {$mrs = $mrs | sort RunspaceId -descending}
3 {$mrs = $mrs | sort ExchangeGuid}
4 {$mrs = $mrs | sort ExchangeGuid -descending}
5 {$mrs = $mrs | sort TargetDatabase}
6 {$mrs = $mrs | sort TargetDatabase -descending}
7 {$mrs = $mrs | sort Alias}
8 {$mrs = $mrs | sort Alias -descending}
9 {$mrs = $mrs | sort DisplayName}
10 {$mrs = $mrs | sort DisplayName -descending}
11 {$mrs = $mrs | sort ExternalDirectoryObjectId}
12 {$mrs = $mrs | sort ExternalDirectoryObjectId -descending}
13 {$mrs = $mrs | sort Guid}
14 {$mrs = $mrs | sort Guid -descending}   
    }

[INT]$counter = 0

[INT]$mrscount = ($mrs).count
[INT]$mintimein = Read-host "Specify the minimum number of minutes"
[INT]$maxtimein = Read-host "Specify the maximum number of minutes"
$mintime = $mintimein +1
$maxtime = $maxtimein +1
Foreach($mr in $mrs){
$rn = get-random -Minimum $mintime -Maximum $maxtime
$ts = [timespan]::fromminutes($rn)
[String]$randomoffest = "{0:HH:mm:ss}" -f ([datetime]$ts.ticks)
$counter++
Write-Progress -Activity "Randomizing incremental sync" -Status "$counter of $mrscount"
Set-MoveRequest $mr.exchangeguid -IncrementalSyncInterval $randomoffest
Write-host "The following IncrementalSyncInterval has been set`: $mr`: $randomoffest"
Clear-Variable rn,ts,randomoffest
}