initial script
This commit is contained in:
36
Exchange/Export-all-mailboxes.ps1
Normal file
36
Exchange/Export-all-mailboxes.ps1
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
$ExportPath = "" #Specify the export path as UNC path!
|
||||||
|
$Mailboxes = Get-Mailbox -ResultSize Unlimited
|
||||||
|
$TotalMailboxes = $Mailboxes.Count
|
||||||
|
$CurrentMailbox = 0
|
||||||
|
|
||||||
|
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!"
|
||||||
Reference in New Issue
Block a user