Move-Mailbox in bulk Script

Hi All,

Want to share three scripts that can be used to move mailboxes each has its on benefits.

Two of them have been written by me & one I have found on internet & customized it.

1.  Simple Move script without any log –>(To execute it  script.ps1 filename.csv)

# script to Move mailboxes by reading the text file

$data = import-csv $args[0]

## Get mailbox ids from text file

foreach ($i in $data)
{
# collect all email addresses

$mailbox = get-mailbox $i.name | move-mailbox -TargetDatabase ‘DEV-EXCH-MAIL\First Storage Group\Mailbox Database’

}

2.  Move-mailbox script with little log(just excute the scripts as path to text file is in the script itself)

$TargetDatabase = “DEV-EXCH-MAIL\Third Storage Group\Rotterdam5”

$SourceFile = “c:\scripts\users.txt”

$a = remove-item c:\scripts\Movelog.txt -ea SilentlyContinue

$error.Clear()

$UserList = Get-Content $SourceFile

foreach($user in $UserList)

{

$message = “Moving User -> ” + $user

write-output $message | out-file -filePath “c:\scripts\MoveLog.txt” -append -noClobber

move-mailbox -Identity $user -TargetDatabase $TargetDatabase -BadItemLimit 5   -Confirm: $false

if($error.Count -ne 0)

{

$message = “User ” + $user + ” failed to move ???????????”

write-output $message | out-file -filePath “c:\scripts\MoveLog.txt” -append -noClobber

$message = “Error:::: ” + $error[0].ToString()

write-output $message | out-file -filePath “c:\scripts\MoveLog.txt” -append -noClobber

$error.Clear()

}

}

3.  Move-mailbox script with mutiple sessions options & log

$TargetDatabase = “DEV-EXCH-MAIL\Third Storage Group\Rotterdam5”

$SourceFile = “c:\scripts\users.txt”

$a = remove-item c:\scripts\Movelog.txt -ea SilentlyContinue

$error.Clear()

$UserList = Get-Content $SourceFile

$userlist | get-mailbox | move-mailbox  -TargetDatabase $TargetDatabase -BadItemLimit 5  -maxthreads 10 -Confirm: $false -ReportFile C:\scripts\Movelog.txt

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s