Posted On June 27, 2019

PowerShell: Export Exchange Mailboxes

kimconnect 0 comments
blog.KimConnect.com >> Codes >> 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 *

Related Post

PowerShell: Update Local Windows Using COM Objects – Legacy Compatible

Although this function requires 'interactive' or console sessions, it can be trigged by Windows Scheduled…

PowerShell: Unjoin Computer From Domain

# unjoinComputerFromDomain.ps1 # Version 0.02 # Notes: # - This function doesn't delete the referenced…

Create a Report of MTU Settings on All Hyper-V Hosts in the Domain/Forest

# mtuReportAllHyperVHosts.ps1 # Ensure that AD management module is available for PS Session function includeRSAT{…