Powerbi token is not generating with Az module Runbook.

Welcome Forums General PowerShell Q&A Powerbi token is not generating with Az module Runbook.

Viewing 1 reply thread
  • Author
    Posts
    • #240230
      Participant
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      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”;
      }

      }

      • This topic was modified 2 months, 2 weeks ago by Joekha38.
    • #240644
      Participant
      Topics: 8
      Replies: 565
      Points: 2,158
      Helping Hand
      Rank: Community Hero

      The error is telling you that you’re trying to provide 2 arguments on line 473 but there are no overloads that accept 2. What is on line 473?

Viewing 1 reply thread
  • You must be logged in to reply to this topic.