Unable to Authenticate to Azure Active Directory using Connect-AzureAD

Hi ,

I am trying to authenticate Azure Active Directory using following code but unable to do so. Please help me

$az = Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $StorageReductionTenant -Subscription $StorageReductionInputFilePathSubscription

# Connect to Azure

Write-Host "az.context"

Write-Host $az.context

$az = Set-AzContext -SubscriptionName $StorageReductionInputFilePathSubscription -DefaultProfile $az.context

# Generate the token

$graphToken = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com/"

Write-Host "GraphToken"

Write-Host $graphToken.token

$aadToken = Get-AzAccessToken -ResourceUrl "https://graph.windows.net"

Write-Host "AadToken"

Write-Host $aadToken.token

Connect-AzureAD -AccountId $az.account.id -TenantId $az.tenant.id -AadAccessToken $aadToken.token -MsAccessToken $graphToken.token

Read more here: Source link