Reputation: 31
I need to publish my power BI reports in multiple workspaces, To publish the same manually is a very lengthy task , I tried crating a Power shell script using CMDLETS but unfortunately I am not getting any API to Re-Publish the already published report,
I have prepared below code in power shell , which will automatically fetch all the PBIX files and ask user to select the workspace to publish the reports, but I am getting error at "Publish-PowerBIReport" because this is not a valid API , Can anyone please help me out.
Import-Module -Name MicrosoftPowerBIMgmt
# Authenticate with your Power BI account
Connect-PowerBIServiceAccount
# Prompt the user to select a target workspace
$workspaces = Get-PowerBIWorkspace | Select-Object Id, Name | Out-GridView -PassThru -Title "Select Target Workspace"
$selectedWorkspaceId = $workspaces.Id
# Get the current folder as the source folder
$folderPath = $PSScriptRoot
# Get all .pbix files from the current folder
$pbixFiles = Get-ChildItem -Path $folderPath -Filter "*.pbix" -File
# Iterate through each .pbix file and publish to the selected workspace
foreach ($pbixFile in $pbixFiles) {
Write-Host "Publishing $($pbixFile.Name) to workspace $($workspaces | Where-Object { $_.Id -eq $selectedWorkspaceId }).Name"
Publish-PowerBIReport -Path $pbixFile.FullName -WorkspaceId $selectedWorkspaceId
}
# Disconnect from the Power BI account
Disconnect-PowerBIServiceAccount
Upvotes: 1
Views: 676
Reputation: 1
In addition to calling New New-PowerBiReport, you'll need to add the "-ConflictAction CreateOrOverwrite" and it will overwrite reports with the same name.
Upvotes: 0
Reputation: 89386
"Publish-PowerBIReport" isn't a thing. Call New-PowerBiReport instead.
Upvotes: 0