39 lines
1.6 KiB
PowerShell
39 lines
1.6 KiB
PowerShell
$ExportPath = "" #Specify the export path as UNC path!
|
|
$Mailboxes = Get-Mailbox -ResultSize Unlimited
|
|
$TotalMailboxes = $Mailboxes.Count
|
|
$CurrentMailbox = 0
|
|
|
|
if (!(test-path $ExportPath)) {mkdir $ExportPath}
|
|
|
|
foreach ($Mailbox in $Mailboxes) {
|
|
$CurrentMailbox++
|
|
|
|
# Start Export Request
|
|
New-MailboxExportRequest -Mailbox $Mailbox.Identity -FilePath "$ExportPath\$($Mailbox.Alias).pst"
|
|
|
|
Write-Host "Export started for: $($Mailbox.Alias). Waiting for completion..."
|
|
|
|
do {
|
|
Start-Sleep -Seconds 5 # Wait before checking again
|
|
|
|
# Check if the mailbox export is still in progress
|
|
$ExportRequest = Get-MailboxExportRequest -Mailbox $Mailbox.Identity | Where-Object { $_.Status -ne "Completed" }
|
|
$ExportStats = Get-MailboxExportRequestStatistics -Mailbox $Mailbox.Identity -ErrorAction SilentlyContinue
|
|
|
|
# Get completion percentage of the current mailbox export
|
|
$MailboxPercentComplete = if ($ExportStats) { $ExportStats.PercentComplete } else { 0 }
|
|
|
|
# Calculate overall progress
|
|
$OverallPercentComplete = [math]::Round((($CurrentMailbox - 1 + ($MailboxPercentComplete / 100)) / $TotalMailboxes) * 100, 2)
|
|
|
|
# Display Progress Bar for Overall Process
|
|
Write-Progress -Activity "Exporting Mailboxes" `
|
|
-Status "Processing: $($Mailbox.Alias) ($MailboxPercentComplete% complete)" `
|
|
-PercentComplete $OverallPercentComplete
|
|
} while ($ExportRequest)
|
|
|
|
Write-Host "Export completed for: $($Mailbox.Alias)"
|
|
}
|
|
|
|
Write-Host "All mailbox exports completed!"
|