Exchange Migration – Restart Apppool

Here is a gret script that restarts the Autodiscover Apppool every 5 minutes until there isn’t any mailboxes left on the oldserver. This one works for Exchange 2016 and 2013

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

do{
$i = 1
$mail = (get-mailbox -server "kakster-oldexchange").count
Restart-WebAppPool MSExchangeAutodiscoverAppPool
Write-host "Restarting AppPool" -ForegroundColor GREEN
"Waiting for 3 minutes"
Start-Sleep -Seconds 300
"Now `$mail is $mail"
$i++
Write-host "Running script for the $i time" -ForegrondColor Red
} Until( $mail -eq 0)