@@ -48,14 +48,15 @@ function Test-CIPPAccessTenant {
4848 $ExchangeStatus = $false
4949
5050 $Results = [PSCustomObject ]@ {
51- TenantName = $Tenant.defaultDomainName
52- GraphStatus = $false
53- GraphTest = ' '
54- ExchangeStatus = $false
55- ExchangeTest = ' '
56- GDAPRoles = ' '
57- MissingRoles = ' '
58- LastRun = (Get-Date ).ToUniversalTime()
51+ TenantName = $Tenant.defaultDomainName
52+ GraphStatus = $false
53+ GraphTest = ' '
54+ ExchangeStatus = $false
55+ ExchangeTest = ' '
56+ GDAPRoles = ' '
57+ MissingRoles = ' '
58+ OrgManagementRoles = @ ()
59+ LastRun = (Get-Date ).ToUniversalTime()
5960 }
6061
6162 $AddedText = ' '
@@ -105,6 +106,37 @@ function Test-CIPPAccessTenant {
105106 $null = New-ExoRequest - tenantid $Tenant.customerId - cmdlet ' Get-OrganizationConfig' - ErrorAction Stop
106107 $ExchangeStatus = $true
107108 $ExchangeTest = ' Successfully connected to Exchange'
109+
110+ # Get the Exchange role definitions and assignments for the Organization Management role group
111+ $Requests = @ (
112+ @ {
113+ id = ' roleDefinitions'
114+ method = ' GET'
115+ url = ' roleManagement/exchange/roleDefinitions?$top=999'
116+ }
117+ @ {
118+ id = ' roleAssignments'
119+ method = ' GET'
120+ url = " roleManagement/exchange/roleAssignments?`$ filter=principalId eq '/RoleGroups/Organization Management'&`$ top=999"
121+ }
122+ )
123+
124+ $ExchangeRoles = New-GraphBulkRequest - tenantid $Tenant.customerId - Requests $Requests
125+
126+ # Get results and expand assigments with role definitions
127+ $RoleDefinitions = ($ExchangeRoles | Where-Object - Property id -EQ ' roleDefinitions' ).body.value | Select-Object - Property id, displayName, description, isBuiltIn, isEnabled
128+ $RoleAssignments = ($ExchangeRoles | Where-Object - Property id -EQ ' roleAssignments' ).body.value
129+ $OrgManagementAssignments = $RoleAssignments | Where-Object - Property principalId -EQ ' /RoleGroups/Organization Management' | Sort-Object - Property roleDefinitionId - Unique
130+ $OrgManagementRoles = $OrgManagementAssignments | ForEach-Object {
131+ $RoleDefinitions | Where-Object - Property id -EQ $_.roleDefinitionId
132+ } | Sort-Object - Property displayName
133+
134+ Write-Warning " Found $ ( $OrgManagementRoles.Count ) Organization Management role assignments in Exchange"
135+ $Results.OrgManagementRoles = $OrgManagementRoles
136+
137+ # TODO: Get list of known good roles and compare against the found roles
138+
139+
108140 } catch {
109141 $ErrorMessage = Get-CippException - Exception $_
110142 $ReportedError = ($_.ErrorDetails | ConvertFrom-Json - ErrorAction SilentlyContinue)
0 commit comments