Skip to content

Commit 7214462

Browse files
committed
Fix nested group lookup and variable naming
Accumulate nested group memberships into a typed List and use AddRange to correctly collect results from Graph queries. Rename loop variables to avoid shadowing ($RoleGroup / $ExpectedGroup) and update matching/log messages accordingly. Include nested groups in the returned Memberships so missing-group detection considers indirect membership; preserve AdminAgents as an error-level issue.
1 parent dde937e commit 7214462

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Modules/CIPPCore/Public/Test-CIPPGDAPRelationships.ps1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,31 @@ function Test-CIPPGDAPRelationships {
5656
'M365 GDAP Privileged Authentication Administrator'
5757
)
5858
$RoleAssignableGroups = $SAMUserMemberships | Where-Object { $_.isAssignableToRole }
59-
$NestedGroups = foreach ($Group in $RoleAssignableGroups) {
60-
Write-Information "Getting nested group memberships for $($Group.displayName)"
61-
New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($Group.id)/memberOf?`$select=id,displayName" -NoAuthCheck $true
59+
$NestedGroups = [System.Collections.Generic.List[object]]::new()
60+
foreach ($RoleGroup in $RoleAssignableGroups) {
61+
Write-Information "Getting nested group memberships for $($RoleGroup.displayName)"
62+
$NestedGroups.AddRange(@(New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($RoleGroup.id)/memberOf?`$select=id,displayName" -NoAuthCheck $true))
6263
}
63-
foreach ($Group in $ExpectedGroups) {
64+
foreach ($ExpectedGroup in $ExpectedGroups) {
6465
$GroupFound = $false
6566
foreach ($Membership in ($SAMUserMemberships + $NestedGroups)) {
66-
if ($Membership.displayName -match $Group) {
67-
Write-Information "Found $Group in group memberships"
67+
if ($Membership.displayName -match $ExpectedGroup) {
68+
Write-Information "Found $ExpectedGroup in group memberships"
6869
$GroupFound = $true
6970
}
7071
}
7172
if (-not $GroupFound) {
72-
if ($Group -eq 'AdminAgents') { $Type = 'Error' } else { $Type = 'Warning' }
73+
if ($ExpectedGroup -eq 'AdminAgents') { $Type = 'Error' } else { $Type = 'Warning' }
7374
$GDAPissues.add([PSCustomObject]@{
7475
Type = $Type
75-
Issue = "$($Group) is not assigned to the SAM user $me. If you have migrated outside of CIPP this is to be expected. Please perform an access check to make sure you have the correct set of permissions."
76+
Issue = "$($ExpectedGroup) is not assigned to the SAM user $me. If you have migrated outside of CIPP this is to be expected. Please perform an access check to make sure you have the correct set of permissions."
7677
Tenant = '*Partner Tenant'
7778
Relationship = 'None'
7879
Link = 'https://docs.cipp.app/setup/gdap/troubleshooting#groups'
7980

8081
}) | Out-Null
8182
$MissingGroups.Add([PSCustomObject]@{
82-
Name = $Group
83+
Name = $ExpectedGroup
8384
Type = 'SAM User Membership'
8485
}) | Out-Null
8586
}
@@ -103,7 +104,7 @@ function Test-CIPPGDAPRelationships {
103104
$GDAPRelationships = [PSCustomObject]@{
104105
GDAPIssues = @($GDAPissues)
105106
MissingGroups = @($MissingGroups)
106-
Memberships = @($SAMUserMemberships)
107+
Memberships = @($SAMUserMemberships + $NestedGroups)
107108
CIPPGroupCount = $CIPPGroupCount
108109
}
109110

0 commit comments

Comments
 (0)