Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I am trying to automate the changing of a datasource for a report with a PowerShell script
When trying to call Get-PowerBIDatasource and Invoke-PowerBIRestMethod to update a datasource when authenticated as a service principal, I am receiving a 403 Unauthorized error.
My SPN is an admin in the workspace and I made sure to take over the dataset.
I did confirm that I can do this with a non-service principal.
Thanks!
I am running into the same issue. I can connect fine with the -ServicePrincipal option. Get-PowerBIWorkspace runs fine. Get-PowerBiReport runs fine as well. The script fails at the following line:
$PbiDataSourcesObject = (Get-PowerBIDatasource -DatasetId $PbiReportObject.DatasetId)
The PS error message I get is:
An error has occurred!!
Error Line Number : 110
Error Command : $PbiDataSourcesObject = (Get-PowerBIDatasource -DatasetId $PbiReportObject.DatasetId)
Error Message : Operation returned an invalid status code 'Forbidden'
Hi @cgstdevops
Before you run Get-PowerBIDatasource and Invoke-PowerBIRestMethod command, make sure you log in using Connect-PowerBIServiceAccount.
Here are similar threads you could refer to:
Powershell API Update datasource
https://docs.microsoft.com/en-us/power-bi/developer/encrypt-credentials
Thanks for the reply.
I am logging in successfully with Connect-PowerBIServiceAccount so that's not the issue. After logging in, I can publish a report, get a report and several other operations, but I am unable to modify datasources from a service account. As mentioned before, I get a 403 Unathorized error. It looks as if service principals are not allowed to call these methods.
I was able to do this with an actual user, so I am currently impersonating a real user to accomplish this automation.
Thanks again and please let me know if there is something I am missing.
Neal
Hi @cgstdevops ,
Can you provide your full powershell script, so that I can try to reproduce the issue ?
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
6 | |
4 | |
2 | |
2 |
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
3 |