List GDAP-relationships with reseller customers using Microsoft Graph and PowerShell

Description

Here’s a script to list GDAP-relationships with your reseller customers based on CSV export in Partner Center, using Microsoft Graph and PowerShell.

Process Description

Prerequisites

Make an export of your reseller customers by:

  • Go to the Customers workspace in Partner Center
  • Go to Indirect resellers in the left-hand menu, chose a reseller and click View customers on the right side.
  • Click Export on the options menu for this reseller.

Now you have the CSV file required for the script to use as reference. No modifications needed.

Example:

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

Details

  • Fill out the following in the script:
    • Name or ID of reseller
    • Path to CSV export from Partner Center
    • Path for generated report

PowerShell Script

# Enter the name or ID of your chosen reseller. This is not required by the script, only as reference in the generated report.
$ResellerName = ""

# Enter the path of your customer list exported from Partner Center.
$ResellerCSV = Import-Csv "./customers.csv" -delimiter "," -Encoding UTF8

# Enter path to where you want to export your report.
$ExportTo = "./export.csv"

$table = @()

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

Write-Output "Fetching all GADP-relationships.."
$gdap = Get-MgTenantRelationshipDelegatedAdminRelationship -All

Write-Output "Looking for reseller customers in GDAP relationships list.."
foreach ($rel in $gdap) {
    foreach ($customer in $ResellerCSV) {
        if ($customer.'Microsoft ID' -eq $rel.Customer.tenantid) {
            $Table += [PSCustomObject]@{
                Reseller = $ResellerName
                Relationship = $rel.DisplayName
                Customer = $rel.Customer.DisplayName
                CustomerTenantID = $rel.Customer.TenantId
                AutoExtendDuration = $rel.AdditionalProperties.autoExtendDuration
                Created = if ($rel.CreatedDateTime) {($rel.CreatedDateTime).tostring("dd.MM.yyy")} else {"No date"}
                Ends = if ($rel.EndDateTime) {($rel.EndDateTime).tostring("dd.MM.yyy")} else {"No date"}
                Status = $rel.status
            }
        }
    }
}
$table | Out-GridView
$table | export-csv $ExportTo -delimiter ";" -force -Encoding UTF8

Disconnect-Graph

Microsoft references

Similar posts