Publish Power BI Report from Sharepoint to Power BI Service using Powershell

Daniel Troyer 6 Reputation points
2022-01-20T17:05:02.167+00:00

Is there a way to publish a Power BI Report saved in a Sharepoint folder to a Power BI Service Workspace using Powershell?

I'm managing a significant number of reports and the GUI process does work, but it's tedious. It would be really nice to whip up a script with some variables and then just crank the publishing process out. I've spent a few hours searching documentation and it appears that Powershell support for Power BI is very limited and this will probably be a feature request.

I think the final product will be something like this:

$Path = Read-Host -Prompt "Enter File Path"
$Name = Read-Host -Prompt "Enter Report Name"
$Destination = Read-Host -Prompt "Enter Destination Workspace"

New-PowerBIReport
-Path (Get-Sharepoint $Path)
-Name $Name
-Workspace (Get-Workspace $Destination)

Additional Powershell components that would be nice:

  1. Configure Scheduled Refresh
  2. Configure refresh failure notifications
  3. Configure App Updates (Low priority)
Microsoft 365 Publishing
Microsoft 365 Publishing
Microsoft 365: Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line. Publishing: The process of preparing, producing, and releasing content for distribution or sale.
604 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Mohammad Majed Asad 155 Reputation points
    2023-05-10T10:47:43.3933333+00:00

    Yes, it is possible to publish a Power BI report saved in a SharePoint folder to a Power BI service workspace using PowerShell. Here are the high-level steps you can follow:

    Connect to the SharePoint site using PowerShell: You can use the SharePoint PowerShell module to connect to the SharePoint site where the report is saved. You will need to authenticate with the appropriate credentials and import the SharePoint PowerShell module.

    Get the report file: Once you are connected to the SharePoint site, you can use PowerShell to get the report file from the SharePoint folder. You can use the Get-ChildItem cmdlet to get the file.

    Connect to the Power BI service using PowerShell: You can use the Power BI PowerShell module to connect to the Power BI service. You will need to authenticate with the appropriate credentials and import the Power BI PowerShell module.

    Publish the report to the Power BI service: Once you are connected to the Power BI service, you can use PowerShell to publish the report to the appropriate workspace. You can use the Import-PowerBIReport cmdlet to import the report.

    Configure scheduled refresh, refresh failure notifications, and app updates: Once the report is published, you can use PowerShell to configure scheduled refresh, refresh failure notifications, and app updates as needed.

    Here is an example PowerShell script that you can use as a starting point:

    mathematicaCopy code
    # Connect to SharePoint
    Connect-PnPOnline -Url <SharePoint site URL> -Credentials (Get-Credential)
    
    # Get report file
    $file = Get-ChildItem -Path <SharePoint folder path> -Filter <report file name>
    
    # Connect to Power BI service
    Connect-PowerBIServiceAccount
    
    # Import report to Power BI service
    Import-PowerBIReport -Path $file.FullName -WorkspaceName <workspace name>
    
    # Configure scheduled refresh, refresh failure notifications, and app updates
    # Insert PowerShell commands here
    

    Note: This is just an example script, and you will need to customize it to fit your specific requirements.