Forum Discussion

PBI_VL's avatar
PBI_VL
Advocate I
8 days ago

Export Powerbi workspace

Hello,

Is it possible to export a workspace with all the objects in it such as pbix, notebooks, ... in an automated way?

Thanks in advance.

Kind regards,

Vanessa Lemmens 

6 Replies

  • Hi PBI_VL​ ,

    Have you tried GIT integration for the workspace?

     

    https://learn.microsoft.com/en-us/fabric/cicd/git-integration/intro-to-git-integration

  • I use below script to download the PBIX files from Workspace.

    Powershell script: just for reports.

    For a Fabric workspace, I'd recommend using the newer Microsoft Fabric REST APIs rather than only the Power BI cmdlets, because they cover notebooks, lakehouses, warehouses, pipelines, and Gen2 dataflows in addition to traditional Power BI artifacts.

    ###################

    Connect-PowerBIServiceAccount -UseDeviceAuthentication | Out-Null

     

    $workspacenm = "<workspacename>"

     

    # Get workspace safely

    $PBIWorkspace = Get-PowerBIWorkspace -Name $workspacenm

     

    if (-not $PBIWorkspace) {

    Write-Error "Workspace '$workspacenm' not found"

    return

    }

     

    $PBIReports = Get-PowerBIReport -WorkspaceId $PBIWorkspace.Id

     

    # Output folder

    $OutPutPath = "C:\temp\$workspacenm\"

     

    if (!(Test-Path $OutPutPath)) {

    New-Item -ItemType Directory -Path $OutPutPath | Out-Null

    }

     

    foreach ($Report in $PBIReports) {

     

    Write-Host "Downloading $($Report.Name)"

     

    # Clean filename (remove invalid characters)

    $SafeName = ($Report.Name -replace '[\\/:*?"<>|]', '_')

     

    # Build output file path safely

    $OutputFile = Join-Path $OutPutPath "$SafeName.pbix"

     

    if (Test-Path $OutputFile) {

    Remove-Item $OutputFile -Force

    }

     

    try {

    Export-PowerBIReport `

    -WorkspaceId $PBIWorkspace.Id `

    -Id $Report.Id `

    -OutFile $OutputFile

     

    Write-Host "Saved: $OutputFile"

    }

    catch {

    Write-Warning "Failed to export $($Report.Name): $_"

    }

    }

    #########################   Notebooks    #######################

    $uri = "https://api.fabric.microsoft.com/v1/workspaces/$WorkspaceId/notebooks/$NotebookId/getDefinition?format=ipynb"

    $result = Invoke-RestMethod `

    -Uri $uri `

    -Headers $headers `

    -Method Post

    #######################

  • v-abhinavmu's avatar
    v-abhinavmu
    Community Support

    Hi PBI_VL​,

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 


    Thank you.

  • Thanks for the tips everyone! We will have a look at this next week.

  • v-abhinavmu's avatar
    v-abhinavmu
    Community Support

    Hi PBI_VL​,

    May I check if this issue has been resolved? If not, Please feel free to contact us if you have any further questions.


    Thank you