我正在尝试自动创建PST。但是,大约50%的时间,我遇到一个错误,因为powershell永远不会检索导出请求的状态,因此这个代码块会陷入无限循环。
$exportIdentity = New-MailboxExportRequest -Mailbox $userID -FilePath "$path$userID.pst" -BadItemLimit 5000 | Select-Object -ExpandProperty identity
Log-Write "Created mailbox export with identity $exportIdentity"
do{
if($debug-eq1){Log-Write "DEBUG - Waiting for the PST to complete - Current Status is $(Get-MailboxExportRequest -Identity "$exportIdentity"|Select-Object -ExpandProperty Status)"}
if((Get-MailboxExportRequest -Identity "$exportIdentity"|Select-Object -ExpandProperty Status)-eq"Queued"){
$exportIdentity | Resume-MailboxExportRequest
}
Start-Sleep -Seconds 20
}until((Get-MailboxExportRequest -Identity "$exportIdentity"|Select-Object -ExpandProperty Status) -eq "Completed" -OR (Get-MailboxExportRequest -Identity "$exportIdentity"|Select-Object -ExpandProperty Status) -eq "Failed" -OR (Get-MailboxExportRequest -Identity "$exportIdentity"|Select-Object -ExpandProperty Status) -eq "CompletedWithWarning")
日志写出了无数的副本
DEBUG - Waiting for the PST to complete - Current Status is
。但是,PST正常完成并成功保存
编辑:如果PST立即(约2分钟)后运行,则会出现这种情况。
答案 0 :(得分:0)
据我所知,这是MS的常见问题。你可以使用这样的东西:
Do {
$status = Get-MailboxExportRequest -name $exportname | Get-MailboxExportRequestStatistics
$finish = $status.StatusDetail
write-host $finish
Start-Sleep 2
Write-Host "Please wait..."
}
Until ($finish -like "Completed")
StatusDetail属性从未让我失望。