After a recent update for Prism, I needed to make some changes to my PowerBI update script. This is updating PowerBI reports with Powershell version 2!
My Powershell scripts have served me well for some time, but after a couple of errors popped up, I found a few extra ways to make it more efficient and also improve how it was handling parameters!
One thing I noticed was that parameters occasionally failed to load correctly after a PBIX upload. This was due to the upload automatically triggering a dataset refresh, which temporarily blocked the API from accepting new parameter values.
Turns out this was due to having scheduled refreshes enabled on the existing dataset. The solution, temporarily disable the scheduled refresh!
So if you have the requirement where you have multiple instances of the same report across the same or different workspaces and need to update them with your latest pbix file this script is for you!
What the script does?
This script will pick up a pbix file then scan over your workspaces (based on when filters you apply). When it finds reports that again match your criteria, it will take a copy of the current parameters, temporarily disable the scheduled refresh, update the pbix file and then load the parameters back in. When its finished, it will reenable the scheduled refresh. In some cases I’ve then set it to perform a refresh straight after to load the data back into the report.
So this means you can upload to the PowerBI service with your pbix file from a single source file, the parameters all remain the same as before, and then we pull in the data based on those parameters and all good to go!
As part of version control, I currently use a parameter to record the current version of my reports. This adds an extra benefit, as I can then use this script to check if the reports are already on the expected version. Just in case the script is interrupted, or we need to deploy in stages.
I then add in the new version number as part of the script and this becomes a great way to track report versions when updating PowerBI reports with PowerShell.
How it works?
- Connects to Power BI Service using Connect-PowerBIServiceAccount.
- Retrieves all Power BI workspaces using Get-PowerBIWorkspace.
- Loops through each workspace and identifies reports whose names start with “AETHER”. (or however best for you)
- For each report:
- Retrieves the dataset parameters.
- Updates the first parameter’s value to a specified version if it doesn’t already match.
- Disables scheduled refresh
- Overwrites the report in the workspace using a specified PBIX file ($FilePath).
- Takes over the dataset to ensure permissions are set correctly.
- Updates the dataset parameters.
- Re-enables the scheduled refresh
Key things you can change
- $DeployVer: The new deployment version to update the first parameter to (e.g., “2025Q2”).
- The reports to find matching a name convention e.g. $_.Name -LIKE ‘*AETHER*’
- $FilePath: The path to the PBIX file used for updating reports.
- Parameter 0 is assumed to represent a version parameter (e.g., “2025Q2”)
# Connect to Power BI Service Account
Connect-PowerBIServiceAccount
# Set the deployment version to be used for updating parameters
$DeployVer = "2025Q2"
# Define the path to the PBIX file to be used for report updates
$FilePath = "C:\MYFILEPATH\REPORT.pbix"
# Define the conflict action for updating reports (e.g., Create or Overwrite existing reports)
$Conflict = "CreateOrOverwrite"
# Retrieve all Power BI workspaces
$workspaces = Get-PowerBIWorkspace -all
# Loop through each workspace
foreach ($workspace in $workspaces) {
# Get all reports in the current workspace with names starting with "AETHER" - adjust the filter as needed
$Reportlist = Get-PowerBIReport -WorkspaceId $workspace.Id | Where-Object -FilterScript {
$_.Name -LIKE '*AETHER*'
}
# Check if any reports were found in the workspace
if ($Reportlist) {
Write-Host "Workspace: $($workspace.Name)" # Log the workspace name
# Loop through each report in the report list
foreach ($Report in $Reportlist) {
Write-Host " Report: $($Report.Name)" # Log the report name
try {
# Retrieve the parameters of the dataset associated with the report
$ParametersJsonString = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/parameters" -Method Get
$Parameters = (ConvertFrom-Json $ParametersJsonString).value # Convert JSON response to PowerShell object
} catch {
Write-Host "Error retrieving parameters: $($_.Exception.Message)"
continue
}
$JsonBase = @{}
$JsonString = $null # Initialize JSON string variable
# Initialize an empty array to hold parameter updates
$UpdateParameterList = New-Object System.Collections.ArrayList
# Loop through each parameter and prepare the update list
foreach ($Parameter in $Parameters) {
$UpdateParameterList.add(@{"name" = $Parameter.name; "newValue" = $Parameter.currentValue})
}
# Check if there are any parameters to update
if ($UpdateParameterList.Count -gt 0) {
# Get the current value of the Version parameter
$currentparam = $UpdateParameterList[0].newValue
Write-Host "Current Parameter Version Value: $currentparam" # Log the current parameter value
# Check if the current parameter value matches the deployment version
if ($currentparam -ne $DeployVer) {
Write-Host "Version does not match. Updating..." # Log the update action
# Display current parameters
$UpdateParameterList.newValue
# Update the first parameter to the new deployment version
$UpdateParameterList[0].newValue = $DeployVer
# Prepare the JSON payload for updating parameters
$JsonBase.Add("updateDetails", $UpdateParameterList)
$JsonString = $JsonBase | ConvertTo-Json
# Define the report name
$ReportName = $Report.Name
# Disable refresh schedule for the dataset
$disableRefreshBody = @"
{
"value": {"enabled": false}
}
"@
try {
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/refreshSchedule" -Method Patch -Body ("$disableRefreshBody")
Write-Host "Refresh schedule disabled for dataset: $($Report.DatasetId)"
} catch {
Write-Host "Failed to disable refresh schedule: $($_.Exception.Message)"
}
try {
# Take over the dataset to ensure permissions are set correctly
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.TakeOver" -Method Post
} catch {
Write-Host "Error taking over dataset: $($_.Exception.Message)"
continue
}
try {
# Update the existing report in the workspace
New-PowerBIReport -Path $FilePath -Name $ReportName -WorkspaceId $workspace.Id -ConflictAction $Conflict
} catch {
Write-Host "Error uploading report: $($_.Exception.Message)"
continue
}
try {
# Update the parameters of the dataset
Start-Sleep 5
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/Default.UpdateParameters" -Method Post -Body $JsonString
} catch {
Write-Host "Error updating parameters: $($_.Exception.Message)"
continue
}
# Reenable refresh schedule for the dataset
$enableRefreshBody = @"
{
"value": {"enabled": true}
}
"@
try {
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/groups/$($workspace.Id)/datasets/$($Report.DatasetId)/refreshSchedule" -Method Patch -Body ("$enableRefreshBody")
Write-Host "Refresh schedule Enabled for dataset: $($Report.DatasetId)"
} catch {
Write-Host "Failed to Enable refresh schedule: $($_.Exception.Message)"
}
Remove-Variable UpdateParameterList, JsonString -ErrorAction SilentlyContinue
} else {
Write-Host "Version already matches. Skipping update." # Log if no update is needed
}
} else {
Write-Host "No parameters found for this dataset." # Log if no parameters are found
}
}
} else {
Write-Host "No reports found in workspace: $($workspace.Name)" # Log if no reports are found in the workspace
}
}
# Log the completion of the script
Write-Host "Script completed."
This approach has saved me hours on PBIX deployment.
If you discover any useful additions or tweaks, feel free to reach out on LinkedIn or by email I’d love to hear how you’ve adapted it.
Thanks for reading!
https://github.com/AetherAdv/powerbi_powershell_updatereports