Forum Discussion
Anonymous
7 years agoNot applicable
Overwrite report when copy/clone via powershell or API?
I am setting up an ops process for elevating reports and I would like to use PowerShell to automate some of the steps, however I have found that the Copy/Clone functions of the Powershell and API see...
Anonymous
4 years agoNot applicable
Hi mbutler71,
If you need more, let me know. I am running into a meeting this morning and kept this "short."
We have code that will find the report id "by name" dynamically, if you need it.
1. Copy pbix files from Drive to "Staging Area" workspace.
New-PowerBIReport -Path $fileToPublish -WorkspaceId $stagingGroupId -ConflictAction CreateOrOverwrite -Verbose
Copying from the drive to Staging will keep the Same ID in place IF the dataset in Staging is the same as the dataset you use for development.
- We use a Golden Dataset that works for all workspaces.
- Publish the Golden Dataset to Staging
- Build reports that connect to the Staging Dataset in the Service
- Publish those reports to Staging with the above command.
2. Update Target report CONTENT from a report in Staging to the Target workspace
#Use UpdateReportContent API to copy content from Staging to Target workspace
# Update "Update Report Content In Group" URL - POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/UpdateReportContent
# Update "Update Report Content In Group" URL - POST https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}/UpdateReportContent
$updateReportUrl = "groups/$GroupId/reports/$reportIdToUpdate/UpdateReportContent"
#Write-Output "$updateReportUrl"
# The Dataset parameters to update
$postParams = @{
sourceReport =
@{
sourceReportId="$($reportIdFromStaging)"
sourceWorkspaceId="$($stagingGroupId)"
}
sourceType = "ExistingReport"
} | ConvertTo-Json
Write-Output "$postParams"
Invoke-PowerBIRestMethod -Url $updateReportUrl -Method Post -Body $postParams -ContentType $content -Verbose
NOTES
The "UpdateReportContent" API will replace the report content and rebind to the target's data source AND keep the report ID in tact.
mbutler71
4 years agoAdvocate I
Awesome, thanks so much for posting. This is working great!
I'm not losing the report id now for our links.
function Update-ReportContent{
# 08.27.2021
param ($stagingReportId, $stagingWorkspaceId, $targetReportId, $targetWorkspaceId, $RestAPIURL)
$updateReportUrl = $RestAPIURL+"groups/$targetWorkspaceId/reports/$targetReportId/UpdateReportContent";
$postParams = @{
sourceReport =
@{
sourceReportId="$($stagingReportId)"
sourceWorkspaceId="$($stagingWorkspaceId)"
}
sourceType = "ExistingReport"
} | ConvertTo-Json
$content = "application/json";
Invoke-PowerBIRestMethod -Url $updateReportUrl -Method Post -Body $postParams -ContentType $content -Verbose;
#Remove the Staging file
Remove-PowerBIReport -Id $stagingReportId -WorkspaceId $stagingWorkspaceId;
}