Skip to content

Commit

Permalink
Merge pull request #1924 from microsoft/bilong-ssv
Browse files Browse the repository at this point in the history
Make SSV validate PF content mailboxes
  • Loading branch information
bill-long authored Jan 29, 2024
2 parents 43be927 + 93e4c26 commit a06d5e6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
5 changes: 3 additions & 2 deletions PublicFolders/SourceSideValidations/Get-FolderData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = $_ }
Expand Down
21 changes: 11 additions & 10 deletions PublicFolders/SourceSideValidations/Get-IpmSubtree.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion PublicFolders/SourceSideValidations/Get-Statistics.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

. .\Get-StatisticsJob.ps1
. $PSScriptRoot\Get-StatisticsJob.ps1

function Get-Statistics {
<#
Expand Down
44 changes: 31 additions & 13 deletions PublicFolders/SourceSideValidations/SourceSideValidations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -193,6 +209,8 @@ try {
$badPermissions | Export-Csv $ResultsFile -NoTypeInformation -Append
}

Write-Progress @progressParams -Completed

# Output the results

$results = New-Object System.Collections.ArrayList
Expand Down

0 comments on commit a06d5e6

Please sign in to comment.