22 June 2012

Another move mailbox script

This script will get mailboxes from a specified database and moves them around to other databases one-by-one and shows progress in PowerShell window.

while (get-mailbox -database mail*)
    {
    "starting hard work"
    if (get-moverequest)
        {
        "got existing move requests, not starting a new one"
        }
    else
        {
        "starting a mailbox move"
        $var1 = get-mailbox -database mail*
        $var2 = $var1 | Get-MailboxStatistics
        $var3 = $var2 | sort itemcount
        New-MoveRequest $var3[0].Displayname
        "started a mailbox move"
        }
    while (get-moverequest)
        {
        for ($i=1; $i -le 60; $i++)
            {
                Write-Host "." -nonewline
                sleep 1
            }
        Write-Host
        get-moverequest | Get-MoveRequestStatistics | select displayname,bytestransferred,bytestransferredperminute,itemstransferred,totalmailboxitemcount,percentcomplete
        if (get-moverequest -movestatus completed)
            {
            "got a completed move request"
            get-moverequest -movestatus completed | select -first 1 | remove-moverequest -confirm:$false
            "deleted that completed request"
            }
        }
    "no ongoing move requests"
    }
"no mailboxes left to move"

No comments:

Post a Comment