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: Set Application CPU Affinity on Remote and Local Computers

# setProcessNameToCpuNumber.ps1$computerName =$env:computername$processname="Chrome";function getProcessors{ param( $computerName=$env:computername ) [int]$processors = 0; $cpuObject = Get-WmiObject -computername $computerName…

Simple Active Directory & DNS Synchronization Script

@echo offGOTO push_or_pull:push_or_pullset /p action="Type in Push, Pull, or Quit. Press Enter for default action…

PowerShell: Stream Reader

Have you ran into scripting situations where opening a file would result in locking from…