Skip to content

Instantly share code, notes, and snippets.

@gscales
Created November 20, 2018 00:34
Show Gist options
  • Save gscales/a2886667b0855c63ad6661ab35ee1aa4 to your computer and use it in GitHub Desktop.
Save gscales/a2886667b0855c63ad6661ab35ee1aa4 to your computer and use it in GitHub Desktop.
function Get-TenantId {
param(
[Parameter(Position = 1, Mandatory = $false)]
[String]$DomainName
)
Begin {
$RequestURL = "https://login.windows.net/{0}/.well-known/openid-configuration" -f $DomainName
Add-Type -AssemblyName System.Net.Http
$handler = New-Object System.Net.Http.HttpClientHandler
$handler.CookieContainer = New-Object System.Net.CookieContainer
$handler.AllowAutoRedirect = $true;
$HttpClient = New-Object System.Net.Http.HttpClient($handler);
$Header = New-Object System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")
$HttpClient.DefaultRequestHeaders.Accept.Add($Header);
$HttpClient.Timeout = New-Object System.TimeSpan(0, 0, 90);
$HttpClient.DefaultRequestHeaders.TransferEncodingChunked = $false
$Header = New-Object System.Net.Http.Headers.ProductInfoHeaderValue("Get-TenantId", "1.1")
$HttpClient.DefaultRequestHeaders.UserAgent.Add($Header);
$ClientResult = $HttpClient.GetAsync([Uri]$RequestURL)
$JsonResponse = ConvertFrom-Json $ClientResult.Result.Content.ReadAsStringAsync().Result
return $JsonResponse.authorization_endpoint
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment