Error connecting to PowerBI Service using Powershell commandlets with Service Principal Approach

I am getting the following error when trying to connect to PowerBI Service using the PowerShell commandlets. It works fine when I try to call Power BI REST APIs from Python. Any inputs will be appreciated.

$secrets = Get-AzKeyVaultSecret -VaultName $keyVaultName -AsPlainText -Name $secretName

$secrets = $secrets | ConvertTo-SecureString -AsPlainText -Force

$credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $clientId, $secrets

Connect-PowerBIServiceAccount -Tenant $tenantId -ServicePrincipal -Credential $credential

Error:

Hi @VijayKommaraju ,

You are encountering an authentication error while attempting to connect to Power BI Service using PowerShell. The error message indicates issues with token acquisition and authorization.

To troubleshoot this issue, you can:

  1. Verify the service principal credentials and ensure they have the necessary permissions.
  2. Check the Azure AD app registration for correct API permissions.
  3. Ensure that the service principal is correctly configured in the Azure Key Vault.
  4. Test connectivity using a simple script or another method to isolate the problem.

For more specific help, try running your query in Data Mentor.

Cheers,

Enterprise DNA Support Team