Skip to content

Commit 4b36d96

Browse files
committed
Enhance mailbox permission report
Added multi-strategy lookup for user mailbox type in Get-CIPPMailboxPermissionReport, returning 'UserMailboxType' in the report. Updated Invoke-ListmailboxPermissions to support UseReportDB and ByUser query parameters, enabling report-based retrieval without a specific user ID.
1 parent 1da358e commit 4b36d96

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ListmailboxPermissions.ps1

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ListmailboxPermissions {
1+
function Invoke-ListmailboxPermissions {
22
<#
33
.FUNCTIONALITY
44
Entrypoint
@@ -10,8 +10,31 @@ Function Invoke-ListmailboxPermissions {
1010
# Interact with query parameters or the body of the request.
1111
$TenantFilter = $Request.Query.tenantFilter
1212
$UserID = $Request.Query.userId
13+
$UseReportDB = $Request.Query.UseReportDB
14+
$ByUser = $Request.Query.ByUser
1315

1416
try {
17+
# If UseReportDB is specified and no specific UserID, retrieve from report database
18+
if ($UseReportDB -eq 'true' -and -not $UserID) {
19+
20+
# Call the report function with proper parameters
21+
$ReportParams = @{
22+
TenantFilter = $TenantFilter
23+
}
24+
if ($ByUser -eq 'true') {
25+
$ReportParams.ByUser = $true
26+
}
27+
28+
$GraphRequest = Get-CIPPMailboxPermissionReport @ReportParams
29+
$StatusCode = [HttpStatusCode]::OK
30+
31+
return ([HttpResponseContext]@{
32+
StatusCode = $StatusCode
33+
Body = @($GraphRequest)
34+
})
35+
}
36+
37+
# Original live query logic for specific user
1538
$Requests = @(
1639
@{
1740
CmdletInput = @{

Modules/CIPPCore/Public/Get-CIPPMailboxPermissionReport.ps1

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,36 @@ function Get-CIPPMailboxPermissionReport {
130130
$UserKey = $_.Name
131131
$UserDisplay = $_.Group[0].User # Use original User value for display
132132

133-
# Build detailed permissions list with mailbox and access rights
134-
$PermissionDetails = $_.Group | ForEach-Object {
135-
[PSCustomObject]@{
136-
Mailbox = $_.MailboxDisplayName
137-
MailboxUPN = $_.MailboxUPN
138-
AccessRights = $_.AccessRights
133+
# Look up the user's mailbox type using multi-strategy approach
134+
$UserMailbox = $null
135+
if ($UserDisplay) {
136+
# Try UPN/primarySmtpAddress lookup (case-insensitive)
137+
$UserMailbox = $MailboxLookup[$UserDisplay.ToLower()]
138+
139+
# If not found, try ExternalDirectoryObjectId lookup
140+
if (-not $UserMailbox) {
141+
$UserMailbox = $MailboxByExternalIdLookup[$UserDisplay]
142+
}
143+
144+
# If not found, try ID lookup
145+
if (-not $UserMailbox) {
146+
$UserMailbox = $MailboxByIdLookup[$UserDisplay]
139147
}
140148
}
149+
$UserMailboxType = if ($UserMailbox) { $UserMailbox.recipientTypeDetails } else { 'Unknown' }
150+
151+
# Build detailed permissions list with mailbox and access rights
152+
$PermissionDetails = @($_.Group | ForEach-Object {
153+
[PSCustomObject]@{
154+
Mailbox = $_.MailboxDisplayName
155+
MailboxUPN = $_.MailboxUPN
156+
AccessRights = $_.AccessRights
157+
}
158+
})
141159

142160
[PSCustomObject]@{
143161
User = $UserDisplay
144-
UserType = if ($UserDisplay -match '@') { 'Email/UPN' } else { 'Display Name' }
162+
UserMailboxType = $UserMailboxType
145163
MailboxCount = $_.Count
146164
Permissions = $PermissionDetails
147165
MailboxCacheTimestamp = $MailboxCacheTimestamp
@@ -154,13 +172,20 @@ function Get-CIPPMailboxPermissionReport {
154172
$MailboxUPN = $_.Name
155173
$MailboxInfo = $_.Group[0]
156174

175+
# Build detailed permissions list with user and access rights
176+
$PermissionDetails = @($_.Group | ForEach-Object {
177+
[PSCustomObject]@{
178+
User = $_.User
179+
AccessRights = $_.AccessRights
180+
}
181+
})
182+
157183
[PSCustomObject]@{
158184
MailboxUPN = $MailboxUPN
159185
MailboxDisplayName = $MailboxInfo.MailboxDisplayName
160186
MailboxType = $MailboxInfo.MailboxType
161187
PermissionCount = $_.Count
162-
Users = ($_.Group | Select-Object -ExpandProperty User | Sort-Object -Unique) -join '; '
163-
Permissions = ($_.Group | ForEach-Object { "$($_.User) ($($_.AccessRights))" }) -join '; '
188+
Permissions = $PermissionDetails
164189
MailboxCacheTimestamp = $MailboxCacheTimestamp
165190
PermissionCacheTimestamp = $PermissionCacheTimestamp
166191
}

0 commit comments

Comments
 (0)