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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Amend Power Shell Script to save and replace older files with new ones everyday

Hi Experts

Totally new to powershell - how can i amend the following code to save the file from specific workspace in Power Bi to folders with the same name as the workspace, every day and delete the older files in the folder with the new files. 

 

Script to run at 1.00am everymorning

 

Workspace name 

Trading

Oil

Stocks

Comm

 

Folder name as above

 

Set-StrictMode -Version "latest"

$ErrorActionPreference="Stop"

<#

    Download all reports from the specified Power BI Workspace

    Ensure you have called login.ps1

#>




[System.Net.WebRequest]::DefaultWebProxy.Credentials=[System.Net.CredentialCache]::DefaultCredentials




$script:WorkspaceName="Soft Launch Power BI Central Workspace"

$OutputFolder=Join-Path -Path $PSScriptRoot -ChildPath "out"

$Script:Reports=$null

$script:Workspace=$null




function CreateOutputFolder{

    if (Test-Path -Path $OutputFolder)

    {

        Write-Host "The output folder $OutputFolder already exists. Not creating"

        return

    }

    New-Item -ItemType Directory -Path $OutputFolder

    Write-Host "The output folder $OutputFolder was created"

}



function DownloadAllReports{

    foreach ($report in $reports){

        Write-Host "----------------------------"

        Write-Host "Downloading report $($report.name)"

        $downloadPath = Join-Path -Path $OutputFolder -ChildPath "$($report.Name).pbix"

        if (Test-Path -Path $downloadPath){

            Remove-Item -Path $downloadPath

            Write-Host "Deleted report file $downloadPath"

        }

        Export-PowerBIReport -WorkspaceId $Workspace.Id  -Id $report.id -OutFile $downloadPath

        $downloadPath

    }

   

}



function GetListOfReports{

    $script:Workspace=Get-PowerBIWorkspace -Name $script:WorkspaceName

    Write-Host "Going to get all reports in the workspace: $script:WorkspaceName"

    $Script:Reports=Get-PowerBIReport -Workspace $script:Workspace

    Write-Host "Found $($reports.Count) reports in the workspace: $script:WorkspaceName"

   

}




CreateOutputFolder

GetListOfReports

DownloadAllReports

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Here is the answer if other User or member what to do this see link

https://sidequests.blog/2021/02/01/exporting-all-your-power-bi-reports-at-once/ 

 

You'll have to do the other POwer Shell work but its a good start

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Here is the answer if other User or member what to do this see link

https://sidequests.blog/2021/02/01/exporting-all-your-power-bi-reports-at-once/ 

 

You'll have to do the other POwer Shell work but its a good start

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.