Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Connect to AAD via WebApp using AzureADUtils or AzureAD PS Modules using a Certificate
# AzureAD Tenant, WebApp and Cert details
$appId = 'a8659035-d8ac-4c5a-a6f2-copiedfromApp&CertCreationScript'
$appObjectId = 'e85499b7-a46e-44c5-9716-copiedfromApp&CertCreationScript'
$resource = ""
$tenantId = "ba7d6538-9c5f-4561-a189-copiedfromApp&CertCreationScript"
$certThumbprint = "5258B9B417A12F211E579D5236BD6C57DEDC7BB7"
$x509cert = Get-ChildItem "cert:\localmachine\my" | ? { $_.Thumbprint -eq $certThumbprint } | Select-Object -First 1
Import-Module AzureADUtils
Import-Module AzureAD
# Connect using PowerShell Modules with the Certificate via the App
Connect-AzureAD -TenantId $tenantId -ApplicationId $appId -CertificateThumbprint $certThumbprint
$AADusers = Get-AzureADUser
# Connect to GraphAPI via the AzureADUtils PS Module
$accesstoken = Get-AzureADGraphAPIAccessTokenFromCert -Certificate $x509cert -ClientId $appId -TenantDomain $tenantId
# Query via GraphAPI and the AzureADUtils PS Module
$users = Invoke-AzureADGraphAPIQuery -AccessToken $accesstoken -TenantDomain $tenantId -GraphQuery "/users?api-version=1.6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.