Creating a New Power BI Workspace using PowerShell

Loading

PowerShell provides a powerful way to create, manage, and automate Power BI workspaces. This guide will walk you through the step-by-step process to create a new Power BI workspace using the MicrosoftPowerBIMgmt module.


Step 1: Prerequisites

1. Install and Import the Power BI PowerShell Module

Ensure that the Power BI module is installed on your system:

# 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 creating a workspace, you must 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: Create a New Power BI Workspace

To create a new workspace, use the New-PowerBIWorkspace command.

# Define workspace name
$workspaceName = "Sales Reports Workspace"

# Create the workspace
New-PowerBIWorkspace -Name $workspaceName

Workspace created successfully!

Example Output

Id                                   Name                      Type      State
------------------------------------ ----------------------- --------- -------
abcd1234-5678-90ef-ghij Sales Reports Workspace Workspace Active

Step 3: Adding Users to the Workspace

Once the workspace is created, you can assign users with specific roles.

# Define variables
$userEmail = "user@yourdomain.com"
$workspace = Get-PowerBIWorkspace -Name $workspaceName
$role = "Admin" # Options: Admin, Member, Contributor, Viewer

# Add user to the workspace
Add-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $userEmail -AccessRight $role

User added to the workspace successfully!


Step 4: Assign a Security Group to the Workspace

Instead of adding users individually, you can assign Azure AD Security Groups.

# Define workspace and group details
$securityGroup = "finance-team@domain.com"

# Add security group
Add-PowerBIWorkspaceUser -Id $workspace.Id -Identifier $securityGroup -AccessRight "Member" -PrincipalType Group

Security Group added successfully!


Step 5: Set Workspace Properties

You can also modify workspace settings like description, capacity assignment, and type.

# Define workspace ID
$workspaceId = $workspace.Id

# Set properties
Set-PowerBIWorkspace -Id $workspaceId -Description "Workspace for sales and analytics reports."

Workspace properties updated!


Step 6: List All Workspaces

To verify the new workspace:

Get-PowerBIWorkspace

Or list a specific workspace:

Get-PowerBIWorkspace -Name "Sales Reports Workspace"

Step 7: Export Workspaces to CSV

To export all workspaces and their details into a CSV file:

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

Workspaces exported successfully!


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 *