Some information is only accessible through the GUI and not by API or abstracted away in a PowerShell module. I got the question if it was possible to be able to get the partner details shown on through code. This is just one of those cases where you can’t have the information in a supported way, but there is a way.

This small piece of code takes a username and password of a global admin account. It uses Connect-AzAccount from the Az.Accounts module to connect to Azure to get a token. The token is used to get another token with a different audience (“”) to be able to get the information from the Microsoft 365 portal.

Was a bit surprised myself to see it works to just throw a bearer token along in the header as I don’t see that happening when browsing through the pages and analyzing the traffic.

The code only works in PowerShell Core. In PowerShell 5.1 you’ll get a message from Invoke-RestMethod about the value size of the cookie being too big for its configured maximum size. If anyone knows how to change this size, or work around this error in another way, please let me know.

$userName = "[email protected]" 
$password = '[email protected]$$w0rd' 

$secStringPassword = ($password | ConvertTo-SecureString -AsPlainText -Force)
$credential = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword)

$tenantId = (Invoke-RestMethod "$($userName.Split("@")[1])/.well-known/openid-configuration" -Method GET).userinfo_endpoint.Split("/")[3]
$uri = "$($tenantId)&api-version=2.1"

$resource = ""

$azContext = (Connect-AzAccount -Credential $credential -ErrorAction Stop).Context
$token =
$null = Disconnect-AzAccount -AzureContext $azContext

$s = Invoke-RestMethod -Method GET -Uri $uri -Headers  @{ "Content-Type"  = "application/json" ; "Authorization" = "Bearer $token" } 

Thanks Jos Lieben for borrowing line 7 ;)