As the title suggest let's see how to publish multiple reports to Power BI Service with PowerShell.
First order of buisness is to ensure scripts are enabled on the system, open PowerShell as Administrator and execute this:
Set-ExecutionPolicy Bypass -Scope CurrentUser -Force
Next either you can use the PowerShell terminal or ISE or Visual Studio code.
You need to makes sure you have installed MicrosoftPowerBIMgmt cmdlet using.
Install-Module -Name MicrosoftPowerBIMgmt
Now you need to have folder that contains the .pbix files, you can either have the files in one parent folder and in case if you have files in the child folder then that's fine too you don't need to move them to the parent folder, PS will eiterate and get the path from the child folders as well.
To generate a list of file run this command:
$PowerBIFiles = Get-ChildItem "C:\PBIX Files" -Recurse -Filter *.pbix
Recurse will make it iterate through child folders, Filter filters out only the Power BI files
To get the path of the files just use a foreach loop to iterate and print out the path or any other details if you like.
I have tried to format the result here but you don't need to, you should use this:
Clear-Host
$PowerBIFiles = Get-ChildItem "C:\PBIX Files" -Recurse -Filter *.pbix
foreach($Pbix in $PowerBIFiles){
Write-Output $Pbix.FullName
}
Now that we have file paths we can invoke PowerBI Login method:
Login-PowerBIServiceAccount
Just sign in into the window that opens up and after that you can comment the line so that you don't login again and again.
Now that we have access to PBI Service and files we can invoke another method which is
New-PowerBIReport
But first you need to get the ID of the workspace on which you want to upload the file, to get the workspace ID just go to the workspace and copy the id from URL
After you get the id just past this code inside the foreach loop
New-PowerBIReport -Path $Pbix.FullName -WorkspaceId "Workspace ID you copied"
Just go back to Power BI Service and you will see that the reports have been uploaded:
Can we disable filter pane in PowerBi with help of powershell and can we able to convert PBIT to PBIX and publish that file using powershell. Can RLS achieve in Powershell