Forum Discussion

willz06jw's avatar
willz06jw
Helper II
3 years ago

PowerShell WriteError: InvokePowerBIRestMethod when authenticated with Connect-PowerBIServiceAccount

Hi,

 

I have a PowerShell script which is erroring out.  When I authenticate with "Login-PowerBI", the script works perfectly.  When I authenticate with Connect-PowerBIServiceAccount it errors out.

 

I am using Connect-PowerBIServiceAccount, because I have to automate the script.

 

Here is the portion of the script which can replicate the issue:


$applicationId = 'AzureAppClientID';
$securePassword = 'AzureAppSecretValue' | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $applicationId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId 'AzureAppTenantID'

Invoke-PowerBIRestMethod -Url 'apps' -Method Get

 

Here are the API permissions in Azure:

 

12 Replies

  • Hi willz06jw 

     

    Just to confirm that you have added allow Service Principals in the Power BI Tenant settings?

    • willz06jw's avatar
      willz06jw
      Helper II

      I have added my service principle (which for people wondering, is automatically created when I registered my Azure App) to the security group which is listed on this Power BI tenant setting, but the PowerShell script still crashes when I authenticate using this method.

       



       

  • willz06jw 

    Which API method are you trying to invoke? If you are trying to inboke a method that is not an admin method, than the service principal must have access to the workspace. 

    • willz06jw's avatar
      willz06jw
      Helper II

      Just the general "Invoke-PowerBIRestMethod -Url 'apps' -Method Get" fails

      • m-colbert's avatar
        m-colbert
        Resolver III

        To be more clear, what URL are you using. That defines which method you are calling.