ユーザーのメールボックスをPSTにリモートでエクスポートできるスクリプトを作成しようとしています(Exchange Server 2010コンソールは、これから実行するサーバーにインストールされています)正しくロードされています)。 L2管理者が手動でタスクを実行する必要がないように、スクリプトを使用して完了しています。ここにMWEがあります。`New-MailboxExportRequest`のプルーゲスバー
$UserID = Read-Host "Enter username"
$PstDestination = "\\ExServer\Share\$UserID.pst"
$Date = Get-Date -Format "yyyyMMddhhmmss"
$ExportName = "$UserID" + "$Date"
try {
New-MailboxExportRequest -Mailbox $UserID -FilePath $PstDestination -Name $ExportName -ErrorAction Stop -WarningAction SilentlyContinue | Out-Null
# Loop through the process to track its status and write progress
do {
$Percentage = (Get-MailboxExportRequest -Name $ExportName | Get-MailboxExportRequestStatistics).PercentComplete
Write-Progress "Mailbox export is in progress." -Status "Export $Percentage% complete" -PercentComplete "$Percentage"
}
while ($Percentage -ne 100)
Write-Output "$UserID`'s mailbox has been successfully exported. The archive can be found at $PstDestination."
}
catch {
Write-Output "There was an error exporting the mailbox. The process was aborted."
}
問題はすぐに我々が輸出を開始すると、タスクはQueued
を取得し、です。場合によっては、エクスポートが非常に長い間キューに入れられていることがあり、スクリプトは現在、タスクの開始時期を把握することができず、終了すると正しく進捗状況を表示できません。エクスポートはバックグラウンドで行われますが、スクリプトはそこに残っています。したがって、エクスポート後のものは実行されず、そのすべてを手動で実行する必要があります。
これを処理する方法を提案してください。
待機タイマーを追加して、エクスポートが開始されたかどうかを確認しました。それは期待どおりにはうまくいきませんでした。