Last active
May 22, 2024 09:47
-
-
Save xxiz/4e5322f00b8c4f378baf4774aa6d2728 to your computer and use it in GitHub Desktop.
check if company uses azure active
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.shawntabrizi.com/aad/does-company-x-have-an-azure-active-directory-tenant/ | |
# Checks if a company uses Azure Active | |
$csv = Import-Csv -Path .\input.csv | |
$output = @() | |
foreach ($line in $csv) | |
{ | |
$companyname = $line.CompanyName | |
$companynameencoded = [System.Net.WebUtility]::UrlEncode($companyname) | |
$GoogleURI = 'https://www.google.com/search?q=' + $companynameencoded + '&btnI' | |
try { | |
$GoogleResult = Invoke-WebRequest -Uri $GoogleURI | |
$CompanyURI = ([System.Uri]$GoogleResult.BaseResponse.ResponseUri).Host.split('.')[-2..-1] -join '.' | |
} catch { | |
write-host $_.Exception | |
$CompanyURI = "error" | |
} | |
$OpenIDConfigURL = 'https://login.microsoftonline.com/' + $CompanyURI + '/.well-known/openid-configuration' | |
try { | |
$OpenIDResult = (Invoke-WebRequest -Uri $OpenIDConfigURL).StatusCode | |
} catch { | |
$OpenIDResult = $_.Exception.Response.StatusCode.value__ | |
} | |
if ($OpenIDResult -eq 200) { | |
$tenant = $true | |
} else { | |
$tenant = $false | |
} | |
$result = [pscustomobject]@{ | |
CompanyName = $companyname.ToString() | |
HomepageURI = $CompanyURI.ToString() | |
OpenIDResult = $OpenIDResult.ToString() | |
HasTenant = $tenant.ToString() | |
} | |
Write-Host $result | |
$output += $result | |
} | |
$output | Export-Csv -Path output.csv -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment