Public/PartnerActions/New-GDAPAccessAssignments.ps1
function New-GDAPAccessAssignments() { param( [Parameter(Mandatory)] [string]$RelationshipId ) Connect-CustomerGraph -CustomerTenantId $PartnerTenantId $AccessAssignmentParams = @($FirstAccessAssignmentParams, $SecondAccessAssignmentParams, $ThirdAccessAssignmentParams) Write-Host "Creating access assignments in parallel.." -ForegroundColor DarkGray $AccessAssignmentParams | ForEach-Object -Parallel { $Params = $using:AccessAssignmentParams $Index = $Params.IndexOf($_) + 1 try { $AccessAssignment = New-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $using:RelationshipId -BodyParameter $_ -ErrorAction Stop Write-Host "Created access assignment [$($Index)/$($Params.Count)]" -ForegroundColor Green } catch { throw "Failed to create access assignment: $_" } try { $AccessAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $using:RelationshipId -DelegatedAdminAccessAssignmentId $AccessAssignment.id -ErrorAction Stop).Status } catch { throw "Failed to get access assignment status: $_" } try { while ($AccessAssignmentStatus -ne "active") { Write-Host "Waiting for access assignment [$($index)/$($Params.Count)] to be active.." Start-Sleep -Seconds 10 $AccessAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $using:RelationshipId -DelegatedAdminAccessAssignmentId $AccessAssignment.id -ErrorAction Stop).Status } Write-Host "Access assignment [$($Index)/$($Params.Count)] active!" -ForegroundColor Green } catch { throw "Failed to wait for access assignment to be active: $_" } } Write-Host "Completed creating access assignments." -ForegroundColor Green } |