Get list of organizations Azure Active Directory (Azure AD) Tenant using API call with help of PowerShell

RamanaReddy V
2 min readJun 30, 2023

When automating tasks involving the statistics of organizations within an Azure AD tenant, API calls are required to retrieve information for all the organizations under the tenant.

APPROACH #1 :

Here are the steps to retrieve the REST API URL for pulling the organization information.

Goto -> Organization Settings -> Azure Active Directory -> Download

Org Settings

Before clicking the Download button, open the browser’s developer tools and navigate to the Network tab. Identify the API call related to the Download button and extract the corresponding GET request API call. This extracted GET request API call is the primary REST API that can be used to retrieve all organizations under a tenant.

Network Tab

Expand the General section in the browser developer tools and capture the URL of the GET request API call. This URL represents the specific API endpoint that can be used to retrieve all organizations under a tenant.

Powershell Script Block:

$ORG_LIST_URL — Expand the General section in the browser developer tools and capture the URL of the GET request API call.


$ORG_LIST_URL = "https://aetestproduct23.vsaex.visualstudio.com/_apis/catalog/Organizations?tenantId=s586c36t-49r7-86t8-550u-1u9q37y83507"

$AZURE_DEVOPS_PAT = "2LTgwMWItODg5MGQ1NGNlZDAxIiwicmgiOiIwLkFTY0FITmRCNTdiR3NFZUFQQTg3TXJCMV"


$AZURE_DEVOPS_AUTHENICATION_HEADER = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$AZURE_DEVOPS_PAT")) }

function Get-ALLOrganizations {
$result = Invoke-RestMethod -Uri $ORG_LIST_URL -Method get -Headers $AZURE_DEVOPS_AUTHENICATION_HEADER -ContentType "application/json" | ConvertFrom-Csv
return $result
}


# 1. GET ALL Test related ORG'S
$testOrgs = Get-ALLOrganizations

$testOrgs
Output

REF:

1. https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/get-list-of-organizations-connected-to-azure-active-directory?view=azure-devops

--

--