Connect-AzureAD from within Windows Build Agent

Copper Contributor



I am trying to connect within a Azure DevOps pipeline using Image Windows-Latest to Azure AD. Overall I am automating a Privilege Identity Management by using the AzureADPreview Module. The Modules installs as expected however the problem is after any command I get the following error in the pipeline.


Error reading JToken from JsonReader. Path '', line 0, position 0.
I am using the following commands to connect inside the pipeline to connect: 


$context = Get-AzContext
$aadToken = Get-AzAccessToken -ResourceTypeName AadGraph
 Connect-AzureAD -AadAccessToken $aadToken.Token -AccountId $context.Account.Id -TenantId $



Any command say Get-AzureADUser all fail with the same error. I have printed out all the param values and they have values. 

1 Reply
I have been doing some more digging. There is one more point that I have to make, that MFA is enabled on the tenant. Decoding the token that is provided by the commands in the MFA enabled flag will not be set.
I have read on other forums that Connect-AzureAD using the AADToken when MFA has been set does not work. Sounds like this could be a non-starters