Move Multiple Mailboxes in Exchange 2007 (Powerhsell)

Receives a List of users to Move (Text File) and Moves them all to a Single DB in Exchange 2007.


Download the Script


 


#############################
# Move-Multiple-Mailbox.ps1 #
# Created By Assaf Miron    #
# Date : 06/11/07           #
#############################

Param(
    [String]$TargetDB,
    [String]$FileToOpen,
    [Boolean]$ValidateOnly=$False
)

function IsHelpRequest
{
    param($argument)
    return ($argument -eq "-?" -or $argument -eq "-help");
}

# Function that displays the help related to this script following
# the same format provided by get-help or <cmdletcall> -?
Function Usage
{
@"

NAME:
`tMove-Multiple-Mailbox.ps1 [-FileToOpen][-TargetDB]

SYNOPSIS:
`tMoves a list of mailboxes listed in an Excel File to
`ta specific Database.

SYNTAX:
`tMove-Multiple-Mailbox.ps1
`t`t[ -FileToOpen <Text File to Open> ]
`t`t[ -TargetDB <MailboxDataBase> ]
`t`t[ -ValidateOnly [True/False] ]

PARAMETERS:
`t-FileToOpen (required)
`t`tAn Text File wich Contains Principle Names of Users to Move
`t-TagretDB (required)
`t`tTarget Databse Name
`t-ValidateOnly (optional)
`t`tDoesn't move the mailboxes but checks if they can move to the target DB

`t-------------------------- EXAMPLE 1 --------------------------

C:\PS> .\Move-Multiple-Mailbox.ps1 -FileToOpen "C:\UsersToMove.txt" -TargetDB "MyEx2007Server\My-Mailbox-DB"

`t-------------------------- EXAMPLE 2 --------------------------

C:\PS> .\Move-Multiple-Mailbox.ps1 -FileToOpen "C:\UsersToMove.txt" -TargetDB "MyEx2007Server\My-Mailbox-DB" -ValidateOnly $true

REMARKS:
`tThe Move Mailbox accours with the Max threads Parameter
`tit will not move mailboxes that have errors
`tor mailboxes that need to preserve thier size.

"@
}


####################################################################################################
# Script starts here
####################################################################################################


# Check for Usage Statement Request
$args | foreach { if (IsHelpRequest $_) { Usage; exit; } }

$arrMailboxes = @()

# Validate the parameters
If ($TargetDB -eq "") { Usage; exit; }
Else {
    If ($FileToOpen -eq "") { Usage; exit; }
    Else {
    write-host $FileToOpen
       
        $arrMailboxes = Get-Content $FileToOpen

        Write-Host "About to move"$arrMailboxes.Count"Mailboxes to"$TargetDB
        $Ans = Read-Host "is This information Correct ? `n[Yes,No]`nDefault(Yes)"
        If ($Ans.Contains("n")) { exit; }
        If ($ValidateOnly -eq $True)
        {
            $arrMailboxes | Move-Mailbox -TargetDatabase $TargetDB -MaxThreads 16 -ValidateOnly
        }
        Else
        {
            $arrMailboxes | Move-Mailbox -TargetDatabase $TargetDB -MaxThreads 16
        }
    }
}

Comments