Managing Power BI Dashboard Access using PowerShell

Loading

Managing Power BI dashboard access is essential for controlling who can view or edit dashboards. With PowerShell, administrators can grant, modify, or revoke access to dashboards efficiently.

This guide will walk you through the step-by-step process to manage Power BI dashboard access using the MicrosoftPowerBIMgmt PowerShell 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 managing dashboard access, connect to Power BI:

# 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 Dashboards in Power BI

To manage access, you need to retrieve dashboard details first:

# Get all dashboards
$dashboards = Get-PowerBIDashboard -All

# Display dashboard details
$dashboards | Select-Object Id, Name, WebUrl, WorkspaceId

Example Output

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

You now have a list of dashboards!


Step 3: Retrieve Current Dashboard Access

To check who has access to a specific dashboard:

# Define dashboard ID
$dashboardId = "abcd1234-5678-90ef-ghij"

# Get access details
Get-PowerBIDashboardUser -DashboardId $dashboardId

You now have the current dashboard permissions!


Step 4: Grant Access to a User

To grant a user view-only access:

# Define dashboard ID and user email
$dashboardId = "abcd1234-5678-90ef-ghij"
$userEmail = "user@example.com"

# Grant Viewer access
Add-PowerBIDashboardUser -DashboardId $dashboardId -PrincipalType User -Identifier $userEmail -AccessRight Viewer

To grant edit access:

Add-PowerBIDashboardUser -DashboardId $dashboardId -PrincipalType User -Identifier $userEmail -AccessRight Contributor

User access granted successfully!


Step 5: Modify User Access

If a user needs upgraded or downgraded permissions, remove their existing access and reassign a new role:

# Remove existing access
Remove-PowerBIDashboardUser -DashboardId $dashboardId -Identifier $userEmail

# Grant new access level
Add-PowerBIDashboardUser -DashboardId $dashboardId -PrincipalType User -Identifier $userEmail -AccessRight Contributor

User access updated!


Step 6: Revoke User Access

To completely remove a user’s access:

Remove-PowerBIDashboardUser -DashboardId $dashboardId -Identifier $userEmail

User access revoked!


Step 7: Export Dashboard Access Report

To export dashboard permissions to a CSV file:

# Get all dashboards
$dashboards = Get-PowerBIDashboard -All

# Loop through each dashboard and get users
$accessList = @()
foreach ($dashboard in $dashboards) {
$users = Get-PowerBIDashboardUser -DashboardId $dashboard.Id
foreach ($user in $users) {
$accessList += [PSCustomObject]@{
DashboardName = $dashboard.Name
DashboardId = $dashboard.Id
UserEmail = $user.Identifier
Role = $user.AccessRight
}
}
}

# Export to CSV
$accessList | Export-Csv -Path "C:\PowerBI_Dashboard_Access.csv" -NoTypeInformation

Dashboard access details exported!


Step 8: 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 *