PowerShell provides an efficient way to delete unused Power BI workspaces and manage workspace lifecycles. This guide will walk you through the step-by-step process of identifying and deleting an unused Power BI workspace 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 deleting a workspace, 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: Identify Unused Workspaces
To find workspaces that haven’t been used recently, use the following command:
# Get all workspaces
$workspaces = Get-PowerBIWorkspace -All
# Filter unused workspaces (modify the condition as per your needs)
$unusedWorkspaces = $workspaces | Where-Object { $_.State -ne "Active" }
# Display the unused workspaces
$unusedWorkspaces | Select-Object Id, Name, Type, State
Example Output
Id Name Type State
------------------------------------ ----------------------- --------- -------
abcd1234-5678-90ef-ghij Old Finance Workspace Workspace Deleted
efgh5678-1234-90kl-mnop Legacy Reports Workspace Workspace Inactive
You now have a list of unused workspaces!
Step 3: Delete an Unused Power BI Workspace
Once you have identified the workspace, delete it using:
# Define workspace name
$workspaceName = "Old Finance Workspace"
# Get workspace details
$workspace = Get-PowerBIWorkspace -Name $workspaceName
# Delete the workspace
Remove-PowerBIWorkspace -Id $workspace.Id -Confirm:$false
Workspace deleted successfully!
Step 4: Delete Multiple Unused Workspaces
To delete all unused workspaces in one go:
# Delete all unused workspaces
$unusedWorkspaces | ForEach-Object {
Remove-PowerBIWorkspace -Id $_.Id -Confirm:$false
}
All unused workspaces have been deleted!
Step 5: Verify Deletion
Run the following command to check if the workspace is still present:
# Check if workspace exists
Get-PowerBIWorkspace -Name "Old Finance Workspace"
If no results are returned, the workspace was successfully deleted.
Step 6: Export Deleted Workspaces Report
To keep a record of deleted workspaces, export the details before deleting them:
$unusedWorkspaces | Export-Csv -Path "C:\Deleted_Workspaces.csv" -NoTypeInformation
Deleted workspaces report saved!
Step 7: Disconnect from Power BI
Once done, disconnect from Power BI:
Disconnect-PowerBIServiceAccount