If you are a Microsoft partner or if you are working with a Microsoft partner, a request to set the management partner id for each subscription sometimes comes up.

This would typically require you to log in to the Azure Portal, find the subscription and the Partner Information settings:

Setting Azure Management Partner Id in the Azure Portal Setting Azure Management Partner Id in the Azure Portal

This is a tedious process especially if you have many subscriptions.


Here is a script which will set the partner id for all subscriptions in a specific Azure AD tenant (or all your subscriptions):


    [Parameter(Mandatory = $true)]

if (-not (Get-InstalledModule -Name "Az.ManagementPartner")) {
    Install-Module -Name "Az.ManagementPartner" -Force

$subscriptions = Get-AzSubscription

if ($TenantId) {
    $subscriptions = $subscriptions | Where-Object TenantId -eq $TenantId

$subscriptions | ForEach-Object {
    $subscription = $PSItem | Set-AzContext | Select-Object -ExpandProperty Subscription | Select-Object -ExpandProperty Name
    $existing = Get-AzManagementPartner -ErrorAction SilentlyContinue | Select-Object -ExpandProperty PartnerId
    if (-not $existing) {
        Write-Verbose -Message "Setting partner id on subscription: $subscription..."
        New-AzManagementPartner -PartnerId $PartnerId | Out-Null
    elseif ($existing -eq $PartnerId) {
        Write-Verbose -Message "Partner id already set on subscription: $subscription..."
    else {
        Write-Verbose -Message "Another partner id: $existing is set on subscription: $subscription, updating..."
        Update-AzManagementPartner -PartnerId $PartnerId | Out-Null

You can call the script like so:

$TenantId = "..."
$PartnerId = "..."

.\Set-PartnerId.ps1 -TenantId $TenantId -PartnerId $PartnerId -Verbose