diff --git a/PublicFolders/SourceSideValidations/Get-FolderData.ps1 b/PublicFolders/SourceSideValidations/Get-FolderData.ps1 index 8eaa76597d..a17575fb81 100644 --- a/PublicFolders/SourceSideValidations/Get-FolderData.ps1 +++ b/PublicFolders/SourceSideValidations/Get-FolderData.ps1 @@ -20,7 +20,8 @@ function Get-FolderData { begin { Write-Verbose "$($MyInvocation.MyCommand) called." $startTime = Get-Date - $serverName = (Get-MailboxDatabase (Get-Mailbox -PublicFolder (Get-OrganizationConfig).RootPublicFolderMailbox.HierarchyMailboxGuid.ToString()).Database).Server.Name + $hierarchyMailboxDatabase = (Get-Mailbox -PublicFolder (Get-OrganizationConfig).RootPublicFolderMailbox.HierarchyMailboxGuid.ToString()).Database + $serverName = (Get-MailboxDatabase $hierarchyMailboxDatabase).Server.ToString() $folderData = [PSCustomObject]@{ IpmSubtree = $null IpmSubtreeByMailbox = $null @@ -88,7 +89,7 @@ function Get-FolderData { } } - $folderData.IpmSubtreeByMailbox = $folderData.IpmSubtree | Group-Object ContentMailbox + $folderData.IpmSubtreeByMailbox = $folderData.IpmSubtree | Group-Object ContentMailboxName $folderData.IpmSubtree | ForEach-Object { $folderData.ParentEntryIdCounts[$_.ParentEntryId] += 1 } $folderData.NonIpmSubtree | ForEach-Object { $folderData.ParentEntryIdCounts[$_.ParentEntryId] += 1 } $folderData.IpmSubtree | ForEach-Object { $folderData.EntryIdDictionary[$_.EntryId] = $_ } diff --git a/PublicFolders/SourceSideValidations/Get-IpmSubtree.ps1 b/PublicFolders/SourceSideValidations/Get-IpmSubtree.ps1 index 4ec9676ea2..fa18754163 100644 --- a/PublicFolders/SourceSideValidations/Get-IpmSubtree.ps1 +++ b/PublicFolders/SourceSideValidations/Get-IpmSubtree.ps1 @@ -78,16 +78,17 @@ function Get-IpmSubtree { } $result = [PSCustomObject]@{ - Name = $Folder.Name - Identity = $Folder.Identity.ToString() - EntryId = $Folder.EntryId.ToString() - ParentEntryId = $Folder.ParentFolder.ToString() - DumpsterEntryId = if ($Folder.DumpsterEntryId) { $Folder.DumpsterEntryId.ToString() } else { $null } - FolderSize = $Folder.FolderSize - HasSubFolders = $Folder.HasSubFolders - ContentMailbox = $Folder.ContentMailboxName - MailEnabled = $Folder.MailEnabled - MailRecipientGuid = $Folder.MailRecipientGuid + Name = $Folder.Name + Identity = $Folder.Identity.ToString() + EntryId = $Folder.EntryId.ToString() + ParentEntryId = $Folder.ParentFolder.ToString() + DumpsterEntryId = if ($Folder.DumpsterEntryId) { $Folder.DumpsterEntryId.ToString() } else { $null } + FolderSize = $Folder.FolderSize + HasSubFolders = $Folder.HasSubFolders + ContentMailboxName = $Folder.ContentMailboxName + ContentMailboxGuid = $Folder.ContentMailboxGuid + MailEnabled = $Folder.MailEnabled + MailRecipientGuid = $Folder.MailRecipientGuid } [void]$ipmSubtree.Add($result) diff --git a/PublicFolders/SourceSideValidations/Get-Statistics.ps1 b/PublicFolders/SourceSideValidations/Get-Statistics.ps1 index 12199ef809..1c74fb045e 100644 --- a/PublicFolders/SourceSideValidations/Get-Statistics.ps1 +++ b/PublicFolders/SourceSideValidations/Get-Statistics.ps1 @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -. .\Get-StatisticsJob.ps1 +. $PSScriptRoot\Get-StatisticsJob.ps1 function Get-Statistics { <# diff --git a/PublicFolders/SourceSideValidations/SourceSideValidations.ps1 b/PublicFolders/SourceSideValidations/SourceSideValidations.ps1 index 8810e47b73..6cd3ff45de 100644 --- a/PublicFolders/SourceSideValidations/SourceSideValidations.ps1 +++ b/PublicFolders/SourceSideValidations/SourceSideValidations.ps1 @@ -117,29 +117,45 @@ try { Write-Progress @progressParams -Status "Step 1 of 6" - $folderData = Get-FolderData -StartFresh $StartFresh -SlowTraversal $SlowTraversal - - if ($folderData.IpmSubtree.Count -lt 1) { - return - } + $mailboxToServerMap = @{} - $script:anyDatabaseDown = $false - Get-Mailbox -PublicFolder | ForEach-Object { + # Validate that all PF mailboxes are available + $anyPFMailboxUnavailable = $false + $pfMailboxes = Get-Mailbox -PublicFolder + foreach ($mailbox in $pfMailboxes) { try { - $db = Get-MailboxDatabase $_.Database -Status + $db = Get-MailboxDatabase $mailbox.Database -Status if ($db.Mounted) { - $folderData.MailboxToServerMap[$_.DisplayName] = $db.Server + $mailboxToServerMap[$mailbox.DisplayName] = $db.Server } else { - Write-Error "Database $db is not mounted. This database holds PF mailbox $_ and must be mounted." - $script:anyDatabaseDown = $true + Write-Warning "Database $db is not mounted. This database holds PF mailbox $mailbox and must be mounted." + $anyPFMailboxUnavailable = $true } } catch { Write-Error $_ - $script:anyDatabaseDown = $true + $anyPFMailboxUnavailable = $true + } + } + + $folderData = Get-FolderData -StartFresh $StartFresh -SlowTraversal $SlowTraversal + + if ($folderData.IpmSubtree.Count -lt 1) { + return + } + + $folderData.MailboxToServerMap = $mailboxToServerMap + + # Validate that all content mailboxes exist + $ipmSubtreeByMailboxGuid = $folderData.IpmSubtree | Group-Object ContentMailboxGuid + foreach ($group in $ipmSubtreeByMailboxGuid) { + $mailbox = Get-Mailbox -PublicFolder $group.Name -ErrorAction SilentlyContinue + if ($null -eq $mailbox) { + Write-Warning "Content Mailbox $($group.Name) not found. $($group.Count) folders point to this invalid mailbox." + $anyPFMailboxUnavailable = $true } } - if ($script:anyDatabaseDown) { + if ($anyPFMailboxUnavailable) { Write-Host "One or more PF mailboxes cannot be reached. Unable to proceed." return } @@ -193,6 +209,8 @@ try { $badPermissions | Export-Csv $ResultsFile -NoTypeInformation -Append } + Write-Progress @progressParams -Completed + # Output the results $results = New-Object System.Collections.ArrayList