Description
Here’s a script to list GDAP-relationships with your reseller’s customers based on CSV export in Partner Center, using Microsoft Graph and PowerShell.
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.
- Requires Microsoft Graph module.
- Requires AdminAgent or Global Administrator role.
Install the module:
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
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
$table = @()
Write-Output "Opening browser for Partner Center authentication.."
Connect-MgGraph -Scopes "DelegatedAdminRelationship.Read.All" -NoWelcome
Write-Output "Fetching all GADP-relationships.."
$Relationships = Get-MgTenantRelationshipDelegatedAdminRelationship -All
Write-Output "Looking for reseller customers in GDAP relationships list.."
foreach ($Relationship in $Relationships) {
foreach ($Customer in $ResellerCSV) {
if ($Customer.'Microsoft ID' -eq $Relationship.Customer.tenantid) {
$Table += [PSCustomObject]@{
Reseller = $ResellerName
Relationship = $Relationship.DisplayName
Customer = $Relationship.Customer.DisplayName
CustomerTenantID = $Relationship.Customer.TenantId
AutoExtendDuration = $Relationship.AdditionalProperties.autoExtendDuration
Created = if ($Relationship.CreatedDateTime) {($Relationship.CreatedDateTime).tostring("dd.MM.yyy")} else {"No date"}
Ends = if ($Relationship.EndDateTime) {($Relationship.EndDateTime).tostring("dd.MM.yyy")} else {"No date"}
Status = $Relationship.status
}
}
}
}
$table | Format-Table
Disconnect-Graph
Explanation
Specify the path to the CSV you exported from Partner Center.
$ResellerCSV = Import-Csv "./customers.csv" -delimiter "," -Encoding UTF8
Connect to Microsoft Graph using the required scope DelegatedAdminRelationship.Read.All, without a welcome message:
Connect-MgGraph -Scopes "DelegatedAdminRelationship.Read.All" -NoWelcome
Fetch all your current GDAP-relationships:
$Relationships = Get-MgTenantRelationshipDelegatedAdminRelationship -All
In this part, we’re doing the following:
- Loop through all partner relationships in $Relationships
- For each relationship, check every row in the CSV ($Customer), which contains the customer tenant IDs under the reseller ($Customer.’Microsoft ID’)
- If the current GADP-relationship customer tenant ID matches the one in the CSV, we write it to the table.
foreach ($Relationship in $Relationships) {
foreach ($customer in $ResellerCSV)
{
if ($customer.'Microsoft ID' -eq $Relationship.Customer.tenantid) {
$Table += [PSCustomObject]@{
Key = Value
}
}
}
}
Options
You can export the table to a CSV file by adding the following at the end of the script:
$table | export-csv "PathToCSV.csv" -delimiter ";" -Encoding UTF8 -NoTypeInformation