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: Script to Search Scheduled Tasks for a Service Account

#$jumpBox=$env:COMPUTERNAME$servers="WEB01"$runas="Network Service"# Admin$who = whoami if ($who.substring($who.length-5, 5) -eq "-admin"){$username=$who;} else {$username=$who+"-admin";}#$password = Read-Host -Prompt…

Basic HTML and HTML5: Use HTML5 to Require a Field

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…

PowerShell: Monitor a Program Wizard for Its Task Completion

Once upon a time in the realm of SysAdmin endless green pastures, there were rampant…
Other project: DragonCoin.com