Skip to content

Instantly share code, notes, and snippets.

@bill-long
Created January 12, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/f8f16f4e8fc6ef443a4430fe25b89b77 to your computer and use it in GitHub Desktop.
Save bill-long/f8f16f4e8fc6ef443a4430fe25b89b77 to your computer and use it in GitHub Desktop.
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"))) {
continue
}
$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