Forum Discussion
New-PowerBIReport is throwing BadRequest error with Connect-PowerBIServiceAccount Silent login
- 11 months ago
Yes, Anjan. I opened a ticket yesterday and have a call scheduled with Microsoft today to go over the issue. Thanks again to everyone for your help and support so far.
Hi
his usually isn’t a “session” problem—it’s permissions/tenant settings. With interactive login you (the user) have rights to publish; with silent login your service principal typically only has read/list rights, so New-PowerBIReport (an upload) returns 400 BadRequest.
-
Enable service principals for the tenant
Power BI Admin Portal → Tenant settings → Allow service principals to use Power BI APIs → Enabled and scoped to a security group that contains your app registration (service principal). Microsoft LearnMicrosoft Fabric Community+1 -
Put the service principal in the workspace with a write-capable role
Add it as Contributor/Member/Admin (Viewer/none won’t work even though listing reports can still succeed). You can do this with PowerShell (notePrincipalType App and the object id of the service principal):$ws = Get-PowerBIWorkspace -Name "Reporting Sandbox"
Add-PowerBIWorkspaceUser -Id $ws.Id `
-PrincipalType App `
-Identifier <SERVICE_PRINCIPAL_OBJECT_ID> `
-AccessRight ContributorDocs for the cmdlet are here. Microsoft Learn
(You can also do it in the workspace’s Access pane in the Service UI.)-
Use correct service principal auth in your script
Your silent block looks fine; this is the canonical pattern:
$sec = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($clientId, $sec)
Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $credDid I answer your question? Mark my post as a solution! Appreciate your Kudos !!
-