Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I want to use Power BI PowerShell module. This is what I have done:
1. I got Power BI Moduel installed in PowerShell
2. I got an app registered with the following permissions:
(This message is shown on the top of the permissions screen)
3. I added the Service Principal to a security group and granted him access in Power BI Admin Portal:
E.g.
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
Solved! Go to Solution.
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
If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.
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.
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
If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
13 | |
2 | |
2 | |
1 | |
1 |
User | Count |
---|---|
20 | |
3 | |
2 | |
2 | |
2 |