Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin 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.
I’m working with multiple Power BI tenants, workspaces and reports. It’s a pain to log out (I’m always logged in with an account for previous report), copy a password from where it’s stored, paste the password, log in, click ‘Publish’ button, select workspace (make sure it’s correct tenant and correct workspace), confirm report replacing, then (optionally, e.g. to switch from stage to production database) open Power BI Service, log out (already did this in Power BI desktop, but need to do the same in Power BI Service), log in, open a workspace, open dataset settings, change parameters (e.g. database IP address), refresh the dataset.
So, I wrote a PowerShell script (based on Power BI Cmdlets for Windows PowerShell). The script uses a simple CSV file to determine what .pbix file goes into which tenant/workspace and what parameters to update (if any). First time it will ask for a password, encrypt and save it. Next time it’s a fully automated process. I just need to select a .pbix file in Total Commander, click Ctrl + Alt + F10 and the report will be published into a designated workspace (no chance to accidentally post it into a wrong tenant/workspace). If required, parameters will be changed and the dataset will be refreshed.
See https://powerofbi.org/2021/01/27/powershell-script-to-publish-power-bi-reports/ for more details and the script itself.
Thank you for your comment @lbendlin ,
>You don't want to be notified about refresh errors?
I use this script for report publishing on development stage. I don't need e-mail notification in this case. Feel free to enable notifications if you need them. I use them only for scheduled refreshing. Also, I can use Power BI REST API based dashboard/report to monitor refreshing statuses.
And you understand correct, by "dataset refreshed" I mean "refresh initiated. I don't care about the wording, but for someone else 'refreshed' will be misleading. Thanks.
Regarding 'refresh request failed' - I'm not sure I understand your proposal. I do not verify if it's failed or not in this code. There is no any error handing in this code anyway. My 'Dataset refresh not required' is for a case when datasetRefresh (parameter from the CSV file) <> "Yes", which literally means 'Dataset refresh not required' (and won't be initiated by the script after report publishing).
#url and body for refreshes API call
$url=$urlbase + "refreshes"
$body = @"
{
"notifyOption": "NoNotification"
}
"@
# Refresh the dataset
Invoke-PowerBIRestMethod -Url $url -Method Post -Body $body
Write-Host " -> dataset refreshed"
}
else {
Write-Host "`nDataset refresh not required"
}
You don't want to be notified about refresh errors?
Please note that "# Refresh the dataset" doesn't actually do that. What it does is initiate a refresh request. You would then have to poll the refreshes history to see if the latest refresh has an end date or not.
Your write-host should say
"Refresh started" }
else
{ write-host "refresh request failed" }
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
7 | |
7 | |
3 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
4 |