Public/PartnerActions/New-GDAPAccessAssignments.ps1
function New-GDAPAccessAssignments() { param( [Parameter(Mandatory)] [string]$RelationshipId ) Connect-CustomerGraph -CustomerTenantId $PartnerTenantId # First access assignment try { $FirstAssignment = New-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -BodyParameter $FirstAccessAssignmentParams Write-Host "Created first access assignment" -ForegroundColor Green } catch { Write-Error "Failed to create first access assignment: $_" } # Second access assignment try { $SecondAssignment = New-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -BodyParameter $SecondAccessAssignmentParams Write-Host "Created second access assignment" -ForegroundColor Green } catch { Write-Error "Failed to create second access assignment: $_" } # Wait for access assignments to be created and active $FirstAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -AccessAssignmentId $FirstAssignment.id).Status $SecondAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -AccessAssignmentId $SecondAssignment.id).Status while($FirstAssignmentStatus -ne "active") { Write-Host "Waiting for first access assignment to be active.." Start-Sleep -Seconds 5 $FirstAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -AccessAssignmentId $FirstAssignment.id).Status } Write-Host "First access assignment active!" -ForegroundColor Green while($SecondAssignmentStatus -ne "active") { Write-Host "Waiting for second access assignment to be active.." Start-Sleep -Seconds 5 $SecondAssignmentStatus = (Get-MgTenantRelationshipDelegatedAdminRelationshipAccessAssignment -DelegatedAdminRelationshipId $RelationshipId -AccessAssignmentId $SecondAssignment.id).Status } Write-Host "Second access assignment active!" -ForegroundColor Green } |