Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
BoNDoK00
Frequent Visitor

PowerBINotAuthorizedException ServicePrincipal despite all access done

I want to use Power BI PowerShell module.  This is what I have done:

1. I got Power BI Moduel installed in PowerShell

BoNDoK00_0-1669999553326.png

 

2. I got an app registered with the following permissions:

BoNDoK00_1-1669999612007.png

(This message is shown on the top of the permissions screen)

BoNDoK00_2-1669999643109.png

 

3. I added the Service Principal to a security group and granted him access in Power BI Admin Portal: 

BoNDoK00_3-1669999708024.png

E.g. 

BoNDoK00_4-1669999745988.png

 

4. I authenticate in Power Shell using this code:

 

$client_id = <>
$tenant_id =  <>
$secret =  <>

$SecurePassword = ConvertTo-SecureString $secret -Force -AsPlainText
$servicePrincipal = New-Object -TypeName PSCredential -ArgumentList $client_id, $SecurePassword

Connect-PowerBIServiceAccount -ServicePrincipal -Credential $servicePrincipal -Tenant $tenant_id

 

5. I try to call APIs from PowerShell: 

 

Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/groups/<Group ID>/users' -Method Get

 

I get the following error message:

 

Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/adm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
 
Invoke-PowerBIRestMethod : Encountered errors when invoking the command: {
  "code": "PowerBINotAuthorizedException",
  "pbi.error": {
    "code": "PowerBINotAuthorizedException",
    "parameters": {},
    "details": [],
    "exceptionCulprit": 1
  }
}
At line:1 char:1
+ Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/adm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], Exception
    + FullyQualifiedErrorId : Encountered errors when invoking the command: {
  "code": "PowerBINotAuthorizedException",
  "pbi.error": {
    "code": "PowerBINotAuthorizedException",
    "parameters": {},
    "details": [],
    "exceptionCulprit": 1
  }
},Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod

 

Can you please assist me to know what did I miss? 

 

Thanks

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @BoNDoK00 , it looks like you are trying to connect using a Service Principal to use the Power BI Admin Rest API.  There is an important part in the documentation:  Enable service principal authentication for read-only admin APIs - Power BI | Microsoft Learn

DarylLynchBzy_0-1670019830438.png

If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.

 

View solution in original post

2 REPLIES 2
halamsjah
Regular Visitor

I have similar issue and got the same error but only for some workspaces.  For most of the other workspaces, the powershell script works fine.

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @BoNDoK00 , it looks like you are trying to connect using a Service Principal to use the Power BI Admin Rest API.  There is an important part in the documentation:  Enable service principal authentication for read-only admin APIs - Power BI | Microsoft Learn

DarylLynchBzy_0-1670019830438.png

If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.

 

Helpful resources

Announcements