Forum Discussion
Powershell script to change Datasource Test to Production
Does someone have a powershell script to change the data source?
For example I want deploy my report to powerBI reporting service from Test to Productios therefore i need to change the datasource from
OTA-DWH-01\Test to OTA-DWH-02\Production
I have a lot of reports so doing it manually will take a lot of time. I now have to open each report indivually and change the datasource.
14 Replies
- mgmeyerPower BI Team
I don't know if there is an existing script for this however it should be pretty straightforward assuming your using Shared DataSources. All you would need to do is issue a PUT request to the following REST API for each of your reports:
http://<server>/reports/api/v2.0/Reports(ID/Path)/DataSources
As for the payload you just need to update the path to the new DataSource. You can refer to the API docs here:
https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0#/Reports/SetReportDataSource
- fbeekvelFrequent Visitor
- AnonymousNot applicable
(Responding to fbeekvel)
Everything I've tried to change the ReportServer connection string, including all 3 articles you've attached. The connection string is local to the file, and the file only. The connection string is read-only in the ReportServer.
I'd love to be proven wrong, but I don't think it's possible. One possible way is to zip the file and change the connection string text, then zip it back up. That's not enterprise-grade though so I haven't pursued it.
- fbeekvelFrequent VisitorI'm pretty sure It works. I have a working script somewhere, I'll see if I can post it tomorrow.
- CasperLehmannFrequent VisitorThere is a Powershell script for this under the Azure-Samples repo. Just remember that you need to register an App to get a Client ID to use with it. https://github.com/Azure-Samples/powerbi-powershell/blob/master/rebindReport.ps1
- AnonymousNot applicable
Does this also work for power bi report server? because when i look into the script it says i need to get the source report info from powerbi service.- CasperLehmannFrequent VisitorI don't know how you connect to the report server, there might be differences. But please report back if you do try it out. I would like to know.
- cchen407etrNew Member
I've tried the powershell script mentioned in this thread but I will always get a 400 bad request.
I've also tried using the API (https://app.swaggerhub.com/apis/microsoft-rs/PBIRS/2.0#/PowerBIReports/UpdatePowerBIReportDataSource) and will also get 400 bad request if I touch the connection string.
If anyone has any other ideas, I'm open to trying as in my organization we have multiple environments I would like to deploy to automatically.
- imichalariasFrequent Visitor
Is there any solution to this problem? We are trying to edit a PBIRS DataSource connecting to an on-premise SQL Server database, using the UpdatePowerBIReportDataSource method.
No matter what we edit (database name, server or user), we get a 400 bad request...
Our PBIRS is 15.0.1102.371 (Mai 2019).
- AnonymousNot applicable
To my knowledge, it is only possible with SSAS-based sources. It's certainly not possible with SQL Server databases.
You're able to attempt this with your report by: "Manage"-->"Data sources"-->"Connection string". Try to edit the connection string. It's possible in SSAS but nothing else I've ran into.