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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
avatorl
Impactful Individual
Impactful Individual

I wrote a PowerShell script to publish any report into a designated workspace in one click!

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.

3 REPLIES 3
mm456
Frequent Visitor

@avatorl @lbendlin  the link on the post is not working.

avatorl
Impactful Individual
Impactful Individual

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).

lbendlin
Super User
Super User

#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" }

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.