Skip to content

Commit 83c33bd

Browse files
update for sendonbehalf
1 parent 8f2841f commit 83c33bd

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ListUserMailboxDetails.ps1

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ Function Invoke-ListUserMailboxDetails {
6464
}
6565
)
6666
Write-Host $UserID
67-
#$username = (New-GraphGetRequest -tenantid $TenantFilter -uri "https://graph.microsoft.com/beta/users/$UserID").userPrincipalName
67+
$usernames = New-GraphGetRequest -tenantid $TenantFilter -uri 'https://graph.microsoft.com/beta/users?$select=id,userPrincipalName&$top=999'
6868
$Results = New-ExoBulkRequest -TenantId $TenantFilter -CmdletArray $Requests -returnWithCommand $true -Anchor $username
69-
69+
Write-Host "First line of usernames is $($usernames[0] | ConvertTo-Json)"
7070
# Assign variables from $Results
7171
$MailboxDetailedRequest = $Results.'Get-Mailbox'
7272
$PermsRequest = $Results.'Get-MailboxPermission'
@@ -113,18 +113,34 @@ Function Invoke-ListUserMailboxDetails {
113113

114114
# Parse permissions
115115

116-
$ParsedPerms = foreach ($PermSet in @($PermsRequest, $PermsRequest2)) {
116+
#Implemented as an arraylist that uses .add().
117+
$ParsedPerms = [System.Collections.ArrayList]::new()
118+
foreach ($PermSet in @($PermsRequest, $PermsRequest2)) {
117119
foreach ($Perm in $PermSet) {
118120
# Check if Trustee or User is not NT AUTHORITY\SELF
119121
$user = $Perm.Trustee ? $Perm.Trustee : $Perm.User
120-
if ($user -ne 'NT AUTHORITY\SELF') {
121-
[PSCustomObject]@{
122-
User = $user
123-
AccessRights = ($Perm.AccessRights) -join ', '
124-
}
122+
if ($user -and $user -ne 'NT AUTHORITY\SELF') {
123+
$null = $ParsedPerms.Add([PSCustomObject]@{
124+
User = $user
125+
AccessRights = ($Perm.AccessRights) -join ', '
126+
})
125127
}
126128
}
127129
}
130+
if ($MailboxDetailedRequest.GrantSendOnBehalfTo) {
131+
$MailboxDetailedRequest.GrantSendOnBehalfTo | ForEach-Object {
132+
$id = $_
133+
$username = $usernames | Where-Object { $_.id -eq $id }
134+
135+
$null = $ParsedPerms.Add([PSCustomObject]@{
136+
User = $username.UserPrincipalName ? $username.UserPrincipalName : $_
137+
AccessRights = 'SendOnBehalf'
138+
})
139+
}
140+
}
141+
if ($ParsedPerms.Count -eq 0) {
142+
$ParsedPerms = @()
143+
}
128144

129145
# Get forwarding address
130146
$ForwardingAddress = if ($MailboxDetailedRequest.ForwardingAddress) {

0 commit comments

Comments
 (0)