@@ -229,25 +229,24 @@ Function Push-ExecOnboardTenantQueue {
229229 if ($AccessAssignments.status -notcontains ' pending' ) {
230230 $OnboardingSteps.Step3.Message = ' Group check: Access assignments are mapped and active'
231231 $OnboardingSteps.Step3.Status = ' succeeded'
232- if ($Item.AddMissingGroups -eq $true ) {
233- $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = ' Checking for missing groups for SAM user' })
234- $SamUserId = (New-GraphGetRequest - uri " https://graph.microsoft.com/beta/me?`$ select=id" ).id
235- $CurrentMemberships = New-GraphGetRequest - uri " https://graph.microsoft.com/beta/me/transitiveMemberOf?`$ select=id,displayName"
236- foreach ($Role in $Item.Roles ) {
237- if ($CurrentMemberships.id -notcontains $Role.GroupId ) {
238- $PostBody = @ {
239- ' @odata.id' = ' https://graph.microsoft.com/v1.0/directoryObjects/{0}' -f $SamUserId
240- } | ConvertTo-Json - Compress
241- try {
242- New-GraphPostRequest - uri " https://graph.microsoft.com/beta/groups/$ ( $Role.GroupId ) /members/`$ ref" - body $PostBody - AsApp $true - NoAuthCheck $true
243- $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = " Added SAM user to $ ( $Role.GroupName ) " })
244- } catch {
245- $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = " Failed to add SAM user to $ ( $Role.GroupName ) - $ ( $_.Exception.Message ) " })
246- }
232+
233+ $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = ' Checking for missing groups for SAM user' })
234+ $SamUserId = (New-GraphGetRequest - uri " https://graph.microsoft.com/beta/me?`$ select=id" - NoAuthCheck $true ).id
235+ $CurrentMemberships = New-GraphGetRequest - uri " https://graph.microsoft.com/beta/me/transitiveMemberOf?`$ select=id,displayName" - NoAuthCheck $true
236+ foreach ($Role in $Item.Roles ) {
237+ if ($CurrentMemberships.id -notcontains $Role.GroupId ) {
238+ $PostBody = @ {
239+ ' @odata.id' = ' https://graph.microsoft.com/v1.0/directoryObjects/{0}' -f $SamUserId
240+ } | ConvertTo-Json - Compress
241+ try {
242+ New-GraphPostRequest - uri " https://graph.microsoft.com/beta/groups/$ ( $Role.GroupId ) /members/`$ ref" - body $PostBody - AsApp $true - NoAuthCheck $true
243+ $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = " Added SAM user to $ ( $Role.GroupName ) " })
244+ } catch {
245+ $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = " Failed to add SAM user to $ ( $Role.GroupName ) - $ ( $_.Exception.Message ) " })
247246 }
248247 }
249- $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = ' SAM user group check completed' })
250248 }
249+ $Logs.Add ([PSCustomObject ]@ { Date = (Get-Date ).ToUniversalTime(); Log = ' SAM user group check completed' })
251250 } else {
252251 $OnboardingSteps.Step3.Message = ' Group check: Access assignments are still pending, try again later'
253252 $OnboardingSteps.Step3.Status = ' failed'
0 commit comments