PowerShell for MigrationWiz

We’re happy to announce the latest version of PowerShell support for MigrationWiz! This will help partners and customers to increase the speed of execution and the ease of management of migration projects.

Unfamiliar with PowerShell? Here’s a quick list of benefits it offers: 

  • Change of pace.  Repetition is not fun.  Removing or minimizing it will improve morale.
  • Consistency.  A scripted solution will run the exact same script every time — no risk of typos, forgetting to complete the task, or doing the task incorrectly.
  • Audit trail.  There are many tasks where having an audit trail would be helpful; perhaps including what task was performed, important results, errors that occurred, when the task ran, who ran it, and so forth.
  • Modular code.  I might spend more time on a particular function than time savings justify, but I can generally reuse or borrow ideas from the code later.
  • Documentation.  Is there documentation for the task?  Is it up to date?  A well written and commented script can generally serve as a helpful base level of documentation that might not exist for a manual task.
  • Education.  Scripting out a task will improve your ability and potentially give you deeper insight into what you’re doing than with the black box of a GUI.
  • Delegation.  With a scripted solution, you can typically delegate more functions closer to the teams best equipped to handle them, giving you more time to focus on the important stuff.

To get started on enabling PowerShell for your MigrationWiz account, click here. To Download the PowerShell Module, click here (this is a download). This module fits in the MigrationWiz SDK.

Here are two example scripts that might come in handy during a project:

Getting Started: Resubmit failed mailbox

Import-Module “C:\Program Files (x86)\BitTitan\BitTitan PowerShell\MigrationPowerShell.dll”

$username = “<define username>”
$password = “<define password>”
$SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword

$connectorPageSize = 50

$connectorOffSet = 0

$t = Get-MW_Ticket -Credentials $cred

$connector = Get-MW_MailboxConnector -Ticket $t -FilterBy_String_Name “ProjectName”

do
{
                         $items = Get-MW_Mailbox -ticket $t -FilterBy_Guid_ConnectorId $connector.Id -PageOffset $connectorOffSet -PageSize $connectorPageSize
                         foreach ($item in $items)
                        {
                                Write-Host “Checking item” $item.ImportEmailAddress “with ID:” $item.Id

                                $lastMigrationAttempt = Get-MW_MailboxMigration -ticket $t -FilterBy_Guid_MailboxId $item.Id -SortBy_CreateDate_Descending | Select-Object -Property MailboxId, CompleteDate, Status, Type, ItemTypes | Select -First 1

                                Write-Host “Found Status:” $lastMigrationAttempt

                                if ($lastMigrationAttempt.Status -eq “Failed”)
                               {                   
                                            Write-Host “Resubmitting Item” $item.ImportEmailAddress
                                            $result = Add-MW_MailboxMigration -Ticket $t -MailboxId $attempt.MailboxId -Type $attempt.Type -ConnectorId $connector.Id -UserId $t.UserId -Status Submitted -ItemTypes $attempt.ItemTypes
                               }
                        }
                        $connectorOffset += $connectorPageSize
                        Write-Host “Switch Page” -foregroundcolor red -backgroundcolor Yellow
}
while($items)

 

Getting Started: Resubmit failed mailbox that has already migrated data

$username = “<define username>”
$password = “<define password>”
$SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $SecurePassword

$t = Get-MW_Ticket -Credentials $cred

$connector = Get-MW_MailboxConnector -Ticket $t -FilterBy_String_Name “ProjectName”

$connectorPageSize = 50

$connectorOffSet = 0

 

do
{
            $items = Get-MW_Mailbox -ticket $t -FilterBy_Guid_ConnectorId $connector.Id -PageOffset $connectorOffSet -PageSize $connectorPageSize

            $lastMigrationAttempt = New-Object -TypeName ‘MigrationProxy.WebApi.MailboxMigration’

            foreach ($item in $items)
           {
                       Write-Host “Testing Item” $item.ImportEmailAddress
                       $lastMigrationAttempt = Get-MW_MailboxMigration -ticket $t -FilterBy_Guid_MailboxId $item.Id -SortBy_CreateDate_Descending | Select -First 1

                       if ($lastMigrationAttempt.Status -eq “Failed”)
                      {
                                    $FullMigrationStat = Get-MW_MailboxStat -Ticket $t -FilterBy_Guid_MailboxId $item.Id
                                    $MigrationInfoStats = $FullMigrationStat.MigrationStatsInfos

                                    foreach ($itemInfo in $MigrationInfoStats)
                                   {
                                           $MigrationStat = $itemInfo.MigrationStats

                                           if (($itemInfo.ItemType -eq “Mail”) -and ($MigrationStat.SuccessCount -ne 0))
                                           {
                                                    Write-Host “Resubmitting Item” $item.ImportEmailAddress -foregroundcolor red -backgroundcolor green
                                                    $result = Add-MW_MailboxMigration -Ticket $t -MailboxId $lastMigrationAttempt.MailboxId -Type $lastMigrationAttempt.Type -ConnectorId $connector.Id -UserId $t.UserId -Status Submitted _

                                                                                   -ItemTypes $lastMigrationAttempt.ItemTypes -Priority 1
                                                    break;
                                           } 
                                  }
                     }
            }
           $connectorOffset += $connectorPageSize
          Write-Host “Switch Page” -foregroundcolor red -backgroundcolor Yellow
}
while($items)