I am updating the powerbi dataset from the Azure Automation account runbook, The code is working fine with AzureRm, but when I changed the code to Az module, then token generation code stop working. installed all the az modules in the Azure Automation account but still no luck.
error: GetAuthToken : Error in generating token: Cannot find an overload for “UserCredential” and the argument count: “2”. At line:473 char:16 + $authToken = GetAuthToken + ~~~~~~~~~~~~ + CategoryInfo : NotSpecified: ( [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,GetAuthToken
Code:
function GetAuthToken
{
try
{
#Add-Type -Path “C:\Program Files\WindowsPowerShell\Modules\Azure\5.1.2\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll”
$resourceAppIdURI = $url_resourceApp
$authority = $url_authority;
$AADcredential = New-Object -TypeName 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential'
-ArgumentList $AadAccountUserName,$AadAccountPassword
Create AuthenticationContext tied to Azure AD Tenant
$authContext = New-Object -TypeName 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext'
-ArgumentList $authority
$authResult = $authContext.AcquireTokenAsync($resourceAppIdURI,$ReportAppClientId,$AADcredential)
if ( ! $authResult -or ! $authResult.Result)
{
return $null;
}
$Token = $authResult.Result.CreateAuthorizationHeader();
Write-Host “Generated Auth Token Successfully”;
return $Token;
}
catch
{
$Error = $_.Exception.Message
Write-Error “Error in generating token: $Error”
return “Error”;
}
}