Skip to content

Commit a6b6162

Browse files
committed
Add support for AllTenants in mailbox permission report
The Get-CIPPMailboxPermissionReport function now handles the 'AllTenants' filter, aggregating mailbox permission data across all tenants. Each result now includes a 'Tenant' property for better identification. This improves reporting capabilities for multi-tenant environments.
1 parent 4b36d96 commit a6b6162

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Modules/CIPPCore/Public/Get-CIPPMailboxPermissionReport.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ function Get-CIPPMailboxPermissionReport {
3333
try {
3434
Write-LogMessage -API 'MailboxPermissionReport' -tenant $TenantFilter -message 'Generating mailbox permission report' -sev Info
3535

36+
# Handle AllTenants
37+
if ($TenantFilter -eq 'AllTenants') {
38+
# Get all tenants that have mailbox data
39+
$AllMailboxItems = Get-CIPPDbItem -TenantFilter 'allTenants' -Type 'Mailboxes'
40+
$Tenants = @($AllMailboxItems | Where-Object { $_.RowKey -ne 'Mailboxes-Count' } | Select-Object -ExpandProperty PartitionKey -Unique)
41+
42+
$AllResults = [System.Collections.Generic.List[PSCustomObject]]::new()
43+
foreach ($Tenant in $Tenants) {
44+
try {
45+
$TenantResults = Get-CIPPMailboxPermissionReport -TenantFilter $Tenant -ByUser:$ByUser
46+
foreach ($Result in $TenantResults) {
47+
# Add Tenant property to each result
48+
$Result | Add-Member -NotePropertyName 'Tenant' -NotePropertyValue $Tenant -Force
49+
$AllResults.Add($Result)
50+
}
51+
} catch {
52+
Write-LogMessage -API 'MailboxPermissionReport' -tenant $Tenant -message "Failed to get report for tenant: $($_.Exception.Message)" -sev Warning
53+
}
54+
}
55+
return $AllResults
56+
}
57+
3658
# Get mailboxes from reporting DB
3759
$MailboxItems = Get-CIPPDbItem -TenantFilter $TenantFilter -Type 'Mailboxes'
3860
if (-not $MailboxItems) {
@@ -162,6 +184,7 @@ function Get-CIPPMailboxPermissionReport {
162184
UserMailboxType = $UserMailboxType
163185
MailboxCount = $_.Count
164186
Permissions = $PermissionDetails
187+
Tenant = $TenantFilter
165188
MailboxCacheTimestamp = $MailboxCacheTimestamp
166189
PermissionCacheTimestamp = $PermissionCacheTimestamp
167190
}
@@ -186,6 +209,7 @@ function Get-CIPPMailboxPermissionReport {
186209
MailboxType = $MailboxInfo.MailboxType
187210
PermissionCount = $_.Count
188211
Permissions = $PermissionDetails
212+
Tenant = $TenantFilter
189213
MailboxCacheTimestamp = $MailboxCacheTimestamp
190214
PermissionCacheTimestamp = $PermissionCacheTimestamp
191215
}

0 commit comments

Comments
 (0)