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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

New-PowerBIReport : Operation returned an invalid status code 'Forbidden'

When I am publishing the report with the New-PowerBIReport Cmdlet in powershell, I am getting the above Error message. Using Azure DevOps Pipeline.

 

Below is the Screen shot for the Reference

saidevops_0-1617245509760.png

 

Status: New
Comments
v-chuncz-msft
Community Support

@saidevops 

 

You may check permission settings and share feedback on this idea.

saidevops
New Member

Thank you for your response,

 

Where do you want me to verify the permissions (IN azure DevOps Organization or Power BI or Azure Active Directory or Service Principal Level).

 

I have implemented the permissions accordingly and I am able to publish the report if i use Power BI actions extension for DevOps. 

 

For your information I am able to display the list of workspaces, which are part of this power BI account. (The code that is written for the same is available in the power shell code snippet)

$workspacelist=Get-PowerBIWorkSpace

$workspacelist

 

When I m tryingto publish the same using the powershell by using the self hosted agent, I am getting this error.

saidevops_1-1617422951550.png

 

Here is the Code Snippet of the powershell that I am using for your reference please.

Installing PowerBI modules:

Install-Module -Name MicrosoftPowerBIMgmt.Profile -Verbose -Scope CurrentUser -Force
Install-Module -Name MicrosoftPowerBIMgmt.Workspaces -Verbose -Scope CurrentUser -Force
Install-Module -Name MicrosoftPowerBIMgmt.Reports -Verbose -Scope CurrentUser -Force

 

#Write powershell code for taking over the dataset.

$datasetname="DemoPowerBISample"

$workspacename="PowerBI_Dev"

$clientsecret="$(ClientSecret)" | ConvertTo-SecureString -AsPlainText -Force

$credentials=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:clientID, $clientSecret

Connect-PowerBIServiceaccount -Serviceprincipal -Credential $credentials -TenantID $env:TenantID

$workspace=Get-PowerBIWorkSpace -Name $workspacename

$workspacelist=Get-PowerBIWorkSpace

Write-host "Printing the Data of Repo path variable"

Get-ChildItem -Path $(reportfolder)

$workspacelist

New-PowerBIReport -Path $(ReportPath) -Name $(ReportName) -Workspace $WorkSpace -ConflictAction CreateOrOverwrite -Verbose

 

Let me know if you need any further info, I am more than happy to share it with you.

v-chuncz-msft
Community Support

@saidevops 

 

You may take a look at this link and check workspace name.