Listing All Power BI Workspaces using PowerShell

Loading

PowerShell provides an easy way to list all Power BI workspaces using the MicrosoftPowerBIMgmt module. This allows administrators to manage workspaces, retrieve details, and automate Power BI operations.


Step 1: Prerequisites

1. Install and Import Power BI Module

Ensure the Power BI PowerShell module is installed:

# Install Power BI module
Install-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser -Force

# Import the module
Import-Module MicrosoftPowerBIMgmt

2. Authenticate to Power BI

Before listing workspaces, you must connect to Power BI:

powershellCopyEdit# 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

Step 2: List All Power BI Workspaces

To retrieve all workspaces in Power BI:

# List all workspaces
Get-PowerBIWorkspace

Output Example:

Id                                   Name                 Type    State
------------------------------------ ------------------- ------- -------
abc12345-6789-xyz0 Sales Analytics Workspace Active
def67890-1234-uvw1 Finance Reports Workspace Active

Step 3: Retrieve Specific Workspace Details

1. List Workspaces by Name

Get-PowerBIWorkspace -Name "Sales Analytics"

2. Get Workspaces for a Specific User

Get-PowerBIWorkspace -User "user@yourdomain.com"

3. Export Workspaces to a CSV File

Get-PowerBIWorkspace | Export-Csv -Path "C:\PowerBI_Workspaces.csv" -NoTypeInformation

Step 4: Filtering Workspaces

1. Show Only Active Workspaces

Get-PowerBIWorkspace | Where-Object { $_.State -eq "Active" }

2. List Workspaces Owned by a User

Get-PowerBIWorkspace | Where-Object { $_.Users -match "user@yourdomain.com" }

Step 5: Disconnect from Power BI

Disconnect-PowerBIServiceAccount

Leave a Reply

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