Last active
April 23, 2018 15:29
-
-
Save tostka/fb36f03d03665f024a0897792aa0f9a9 to your computer and use it in GitHub Desktop.
Simple, 'Toss the most recent NN mbxs into the air & let Automatic Mailbox Provisioning redistribute them onto new dbs' script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# -- TRIMMED GIST -- SEE FULL SCRIPT AT GITHUB FOR DETAILS | |
https://github.com/tostka/PowerShell/blob/master/ExchangeScripts/move-MailboxesMostRecent.ps1 | |
-#> | |
$domaincontroller="DOMAINCONTROLLER" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Using BatchName:$($BatchName)" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Moving most recent $($Number) mailboxes" ; | |
if($db=get-mailboxdatabase $database -domaincontroller $domaincontroller ){ | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Moving most recent $($Number) mailboxes" ; | |
if($mbxs = (get-mailbox -Database $db.identity -DomainController $domaincontroller)) { | |
if($showdebug){write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):($($mbxs.count) raw mailboxes returned in db)" }; | |
$mbxs = ($mbxs |sort whencreated)[(-1*$Number)..(-1)] ; | |
if($showdebug){write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):($($mbxs.count) net mailboxes subject to move)" }; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):Filtered most recent mailboxes $($mbxs.count) returned" ; | |
$BatchName="ExMoves-db-$($db.name)-REBAL-$(get-date -format 'yyyyMMdd-HHmmtt')"; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):BATCHNAME:$($BatchName)" ; | |
foreach($mbx in $mbxs){ | |
"==$($mbx):" ; | |
write-verbose -verbose:$true "$((get-date).ToString('HH:mm:ss')):WHATIF:$($whatif):Moving Mbx:$($mbx.alias):$($mbx.displayname):$($mbx.whencreated)" ; | |
$spltMove=@{ | |
identity=$mbx.alias ; | |
BadItemLimit=100 ; | |
AcceptLargeDataLoss=$true ; | |
suspend=$true ; | |
batchname=$BatchName ; | |
domaincontroller=$domaincontroller ; | |
whatif=$($whatif) ; | |
} ; | |
if($showDebug){Write-Verbose -Verbose:$true "$((get-date).ToString("HH:mm:ss")):Executing New-MoveRequest with settings:"; $spltMove|out-string } ; | |
New-MoveRequest @spltMove ; | |
} ; # loop-E | |
if(!$whatif){ | |
write-host -foregroundcolor green "$((get-date).ToString('HH:mm:ss')):MOVEREQUESTS STATUS, BATCH:$(BatchName):" ; | |
Get-MoveRequest -BatchName $BatchName -domaincontroller $dc | ft -auto DisplayName,Status,TargetDatabase; | |
} ; | |
} else { | |
throw "NO MATCHING MAILBOXES FOUND IN DB:$($DATABASE)" ; | |
} ; | |
} else { | |
throw "specified db $($database) not found" ; | |
} ; | |
<# -- TRIMMED GIST -- SEE FULL SCRIPT AT GITHUB FOR DETAILS -#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment