Listing All Power BI Reports using PowerShell

Loading

PowerShell provides an efficient way to list all reports in Power BI, including details like report names, workspace locations, and IDs. This guide will walk you through step-by-step instructions on how to retrieve all Power BI reports using the MicrosoftPowerBIMgmt module.


Step 1: Prerequisites

1. Install and Import the Power BI PowerShell Module

Ensure that the Power BI PowerShell module is installed:

# Install the Power BI module (if not installed)
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser -Force

# Import the module
Import-Module MicrosoftPowerBIMgmt

2. Authenticate to Power BI

Before listing reports, connect to the Power BI service:

# Connect interactively
Connect-PowerBIServiceAccount

For automation, use a Service Principal:

# Define credentials
$clientId = "your-client-id"
$clientSecret = "your-client-secret"
$tenantId = "your-tenant-id"

# Convert secret to secure string
$secureSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($clientId, $secureSecret)

# Connect using Service Principal
Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $tenantId -ClientId $clientId -Credential $credential

Now you’re connected to Power BI!


Step 2: List All Power BI Reports

To list all reports across workspaces, use:

# Get all reports
$reports = Get-PowerBIReport -All

# Display report details
$reports | Select-Object Id, Name, WebUrl, DatasetId, WorkspaceId

Example Output

Id                                   Name                     WebUrl
------------------------------------ ---------------------- ----------------------------
abcd1234-5678-90ef-ghij Sales Report https://app.powerbi.com/reports/abcd1234
efgh5678-1234-90kl-mnop Finance Report https://app.powerbi.com/reports/efgh5678

You now have a list of all reports!


Step 3: List Reports for a Specific Workspace

To list reports from a specific workspace, first retrieve the workspace ID:

# Define workspace name
$workspaceName = "Sales Analytics"

# Get workspace details
$workspace = Get-PowerBIWorkspace -Name $workspaceName

# List reports in the workspace
Get-PowerBIReport -WorkspaceId $workspace.Id | Select-Object Id, Name, WebUrl

Reports for the specified workspace are listed!


Step 4: Export Reports List to CSV

To save report details to a CSV file:

$reports | Export-Csv -Path "C:\PowerBI_Reports.csv" -NoTypeInformation

Reports exported successfully!


Step 5: Disconnect from Power BI

Once done, disconnect from Power BI:

Disconnect-PowerBIServiceAccount

Leave a Reply

Your email address will not be published. Required fields are marked *