Wednesday, April 6, 2011

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

1 comment:

  1. Woah! I'm really loving the template/theme of this website. It's simple, yet effective.
    A lot of times it's hard to get that "perfect balance" between user friendliness and visual appearance. I must say you've done a fantastic job with this.

    Additionally, the blog loads extremely fast for me on Chrome.
    Outstanding Blog!

    ReplyDelete