PowerShell: Export Exchange Mailboxes

Export 1 mailbox
$userAlias="kungfu.panda"
$storageUNC="\\FILESHERVER01\Backups\PSTs"

# Import Exchange Management Powershell
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

$mailboxRequest=(New-MailboxExportRequest -Mailbox $userAlias -FilePath "$storageUNC\$userAlias.pst").Mailbox

function monitorCompletion($check){
$migrationStatus=(Get-MailboxExportRequest -Mailbox $check).Status
$completed=$migrationStatus -like 'Completed'
if (!($completed)){
Write-Host -NoNewline "Waiting for $check batch to complete..."
$dots=50
$timeout=10 #10 seconds
while (!($completed)) {
$dots-=1;
#$timeout-=2; # Timeout is optional
#if($timeout -lt 0){"$timeout seconds have passed. Skip this waiting."; continue;}
if ($dots -eq 0){Write-Host ".";$dots=50;} # reload dots
else {Write-Host -NoNewline "."}
Start-Sleep -s 2
$completed.Refresh()
}
}
Write-Host "$check batch is completed."
}

# monitorCompletion $userAlias
# There's problem with the "Refresh()" function on 2010 PowerShell instances. Thus, no progress dots can be generated from this function.
Export all Mailboxes
$storageUNC="\\FILESHERVER01\Backups\PSTs"

# Import Exchange Management Powershell
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

function monitorCompletion($check){
$migrationStatus=(Get-MailboxExportRequest -Mailbox $check).Status
$completed=$migrationStatus -like 'Completed'
if (!($completed)){
Write-Host -NoNewline "Waiting for $check batch to complete..."
$dots=50
$timeout=10 #10 seconds
while (!($completed)) {
$dots-=1;
#$timeout-=2; # Timeout is optional
#if($timeout -lt 0){"$timeout seconds have passed. Skip this waiting."; continue;}
if ($dots -eq 0){Write-Host ".";$dots=50;} # reload dots
else {Write-Host -NoNewline "."}
Start-Sleep -s 2
$completed.Refresh()
}
}
Write-Host "$check batch is completed."
}

$userAliases=Get-Mailbox -ResultSize unlimited
foreach ($userAlias in $userAliases){
New-MailboxExportRequest -Mailbox $userAlias -FilePath "$storageUNC\$userAlias.pst"
sleep 10;
# monitorCompletion $userAlias;
}

Leave a Reply

Your email address will not be published. Required fields are marked *