How to get all Azure DevOps organizations in your AzureAD directory using PowerShell

How to get all Azure DevOps organizations in your AzureAD directory using PowerShell

ยท

1 min read

I was in a situation where I needed to audit some DevOps-related data. What was my surprise when I realized that there is no programmatic way to get all existing Azure DevOps organizations (at least uncle Google didn't offer me any).

Sure you can visit https://dev.azure.com/<yourOrganizationName>/_settings/organizationAad and download csv file with these information manually. ๐Ÿ‘‡ image.png

But I needed a programmatic way, so I have created the PowerShell function Get-AzureDevOpsOrganizationOverview.


How Get-AzureDevOpsOrganizationOverview function works

There are two main parts:

  • Authentication to Azure DevOps
  • Getting the data

Authenticate to Azure DevOps

It took me a while to realize that MSAL authentication is the way to go. I've found inspiration in the function GetCurrentContext (placed in ContextHelper.ps1) from a great auditing module AzSK.ADO.

For MSAL auth. I've used the MSAL.PS module's function Get-MsalToken.

So there is an obvious requirement and that is to have MSAL.PS module installed

The result ๐Ÿ‘‡ image.png

Get the DevOps organizations data

I've used Developer mode (F12) in the Chrome browser to get the URI ๐Ÿ‘‡ image.png

And then just used it in the Invoke-WebRequest like this ๐Ÿ‘‡ image.png


image.png

How to use it

ย