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

Domain Name Records Overview: A-record, MX, DKIM, SPF, SRV

A RECORD (A-host): - What: address record (A-record) specifies the IP address(es) of a given…

PowerShell: Get Executable Version and File Location

# Quick method to obtain computernames of all nodes in a cluster and adjoin result…

PowerShell: Install Visual Studio 2019 Community Version

# Install Chocolateyif (!(Get-Command choco.exe -ErrorAction SilentlyContinue)) {Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))}#…