Tommy Gjertsen

Enable GDAP auto-extend using Microsoft Graph and PowerShell

16 Aug 2024technical

Description

The following applies to Microsoft CSP and Partner Centers. If you don’t have enabled auto-extend enabled on your customer GDAP-relationships, you can use this script to modify the property called “autoExtendDuration”, to enable it.

Examples


GDAP autoExtendDuration illustration

Notes

You can find more under Microsoft GDAP FAQ

Prerequisites

Example:

Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force

Details

Normally, we’d use Set-MgTenantRelationshipDelegatedAdminRelationship to set the autoExtendDuration property, but this commandlet is currently missing implementation to handle a required If-Match in the request header. See Github issue.

The workaround is to use Invoke-MgGraphRequest as demonstrated with this script.

PowerShell Script

Write-Output "Opening browser for Partner Center authentication.."
Connect-MgGraph -Scopes "DelegatedAdminRelationship.ReadWrite.All"

Write-Output "Fetching GDAP-relationships.."
$gdap = Get-MgTenantRelationshipDelegatedAdminRelationship -All | Where-Object {($_.status -eq "created" -or $_.status -eq "active") -and $_.EndDateTime -lt $(get-date).AddDays(60) -and ($_.AdditionalProperties.autoExtendDuration -eq "PT0S" -or $_.AutoExtendDuration -eq "00:00:00")}

$total = $gdap.count
$count = 0
$params = @{autoExtendDuration = "P180D"}

Write-Output "Modifying autoExtendDuration values.."
Foreach-Object ($rel in $gdap) {
    $count++
    Write-Progress -Activity "Enabling auto-extend on: $($rel.displayname)" -Status "($count/$total)"
    $GDAPAutoExtend = $null
    try {
        Invoke-MgGraphRequest -Uri "v1.0/tenantRelationships/delegatedAdminRelationships/$($rel.id)" -Method PATCH -Body $params -Headers @{"If-Match" = $rel.AdditionalProperties['@odata.etag']} | out-null
    }
    catch {
        "$($rel.DisplayName): $($_.Exception.Message)"
    }
}
Write-Output "Finished ($count/$total)"

Disconnect-Graph

Microsoft references

Similar posts