Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
When performing New-MailboxRestoreRequest against a PF mailbox, public folders that don't exist in the hierarchy do not get created automatically. The report shows the missing folders. This script uses that report to recreate the hierarchy, so that the restore succeeds on the second attempt.
# Make sure the report is in the $report variable. Then just copy and paste this into Exchange Management Shell.
$report.Report.MailboxVerification | WHERE { $_.FolderIsMissing } | % {
$path = $_.FolderSourcePath
if (!($path.StartsWith("/IPM_SUBTREE"))) {
$path = $path.Substring(12).Replace("/", "\")
$lastSlashIndex = $path.LastIndexOf("\")
$folderName = $path.Substring($lastSlashIndex + 1)
if ($lastSlashIndex -eq 0) {
"Creating root folder: $folderName"
New-PublicFolder $folderName
} else {
$parent = $path.Substring(0, $lastSlashIndex)
"Creating new child folder in parent: $parent"
"Child folder: $folderName"
New-PublicFolder -Path $parent -Name $folderName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.