Submitted By: Phil Braniff

Sample script that loads the new server with users across all of the storage groups/databases on the new server (round robin).

PowerShell
Edit|Remove
# ============================================================================================ 
# NAME: SprayMoves.ps1
#
# DESCRIPTION:
#   Given an input file with a list of SMTP addresses this script will
#   move those mailboxes to a specified server across all (or part)
#   of the databases on the server.
#
# EXAMPLES:
#
#   > .\SprayMoves mblist.txt
#
# VERSION: 1.0
#
# VERSION HISTORY:
#   1.0: [Phil Braniff] Modification to Initial script provided from Doug Lawty(msft).
#
# ==============================================================================================
# =  WARNING: Oddity about this script.                                                        =
# =    Remove all trailing blanks from the text input. If there are trailing blanks the        =
# =    objects will not be found and the update will fail.                                     =
# ==============================================================================================
# =  You can use UltraEdit32 'Format' + 'Trim Trailing Spaces' function to clean up input file.=
# ==============================================================================================

param(
  [string] $inputFile = (Read-Host -Prompt "Input file" )
)

$AdminSessionADSettings.ViewEntireForest = $true;

# Check to see if the provided file name exists.
if ( Test-Path $inputFile ) {
  $addressList = Get-Content $inputFile;
  # The file can either have a header row or not. If it does, remove it.
  if ( ! ($addressList[0].Contains("@")) ) { $addressList = $addressList[1..($addressList.Length - 1)]; }
} else {
  Write-Host "Specified address list does not exist!" -ForegroundColor Red
  exit;
}

$serverName = (Read-Host -Prompt "Supply the destination Server name for these moves:" )
$database = "\SG1\1MBX1","\SG2\2MBX1","\SG3\3MBX1","\SG4\4MBX1","\SG5\5MBX1","\SG6\6MBX1","\SG7\7MBX1","\SG8\8MBX1","\SG9\9MBX1","\SG10\10MBX1","\SG11\11MBX1","\SG12\12MBX1","\SG13\13MBX1","\SG14\14MBX1","\SG15\15MBX1","\SG16\16MBX1","\SG17\17MBX1","\SG18\18MBX1","\SG19\19MBX1","\SG20\20MBX1","\SG21\21MBX1","\SG22\22MBX1","\SG23\23MBX1","\SG24\24MBX1","\SG25\25MBX1","\SG26\26MBX1","\SG27\27MBX1","\SG28\28MBX1","\SG29\29MBX1","\SG30\30MBX1","\SG31\31MBX1","\SG32\32MBX1","\SG33\33MBX1","\SG34\34MBX1","\SG35\35MBX1","\SG36\36MBX1","\SG37\37MBX1","\SG38\38MBX1","\SG39\39MBX1","\SG40\40MBX1","\SG41\41MBX1","\SG42\42MBX1"
$i = 0
foreach ( $address in $addressList ) {
  $mailbox = Get-Mailbox $address;
  $db = $($serverName)+($database[$i])
  Move-Mailbox -id $address -targetdatabase $db -BadItemLimit 50 -PreserveMailboxSizeLimit:$true -Confirm:$False -whatif;
  $i = $i+1
  if ($i -gt 41) 
  {
     $i = 0
  }
}