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

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

Reply
Anonymous
Not 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 seem to duplicate the report instead of overwriting when copying between workspaces. The dataset can be ignored or overwritten but the report seems to always duplicate. Has anyone successfully copied a report between workspaces without duplicating? I am hesitant to delete the original report before copy as I think that will break Dashboards and permissions?

The theory is that we will have three workspaces, OpsGroup1_Dev, OpsGroup1_Test, and OpsGroup1 where we push the Dev report either via the Desktop or PowerShell, then copy the report to Test/Prod as park of an elevation (like OctoDeploy or similar).

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous ,

I'd like to suggest you refer to following blog about use powershell and rest api to duplicate workspace:

Duplicate workspaces using the Power BI REST APIs: a step-by-step tutorial

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Thank you for the suggestion Xiaoxin. I have followed that guide, and can move datasets (or pbix with embedded datasets) around without duplicating.

 

My issue now is with .pbix files without embedded datasets (i.e. ones built when directly connected to a cloud dataset). I can import these with my previous code to the workspace of the associated dataset, however the code fails when uploading to a different workspace. If I try Cloning by first uploading to the initial workspace then cloning to the new workspace I get duplicates if the report already exists in the target space. The comments in section 4 (Cloning) of the referenced article seem to indicate that Cloning is the only way to move a report if the dataset exists, but that causes me issues. I don't think I should delete the report in the target workspace first as that might remove Dashboards and permissions?

 

Maybe I am going about this the wrong way or am missing something with the PowerBI service... How should reports flow through DEV/TEST/PROD in an enterprise environment? I envision having a dataset upon which many reports may be built (and then extended to Dashboards), and I'd like to have an automated process that "deploys" a report to PROD as opposed to manually using the desktop to repoint the dataset and republishing. 

Anonymous
Not applicable

Were you able to solve this efficiently?

I am facing the same issue.

The two options I am exploring are:

1.  Use Copy-PowerBIReport and the find and delete the old report, but this negatively impacts references to the existing report

 

2. Use New-PowerBIReport with the "Overwrite" option.  In this case, however, I have to find the reportId and then rebind it.

 

Thanks,

Chris

Has anybody solved this?

I want the PBI Service to overwrite/update my report and not give me back a new Report Id everytime I deploy to a workspace(/environment).

I can use the "Import" REST API and/or the MicrosoftPowerBIMgmt New-PowerBIReport cmdlet to post an updated report, but both will give me a new Report Id for the report which will break all links and references to the original report of the same name.

Anonymous
Not 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.

 

  1. We use a Golden Dataset that works for all workspaces.
  2. Publish the Golden Dataset to Staging
  3. Build reports that connect to the Staging Dataset in the Service
  4. 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.

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; 
}

 

 

 
Anonymous
Not applicable

Hi @Anonymous ,

Maybe you can try to use template app to share your contents:

What are Power BI template apps?

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.