Assigning Users to Power BI Workspaces using PowerShell

Loading

Managing user access to Power BI workspaces is essential for collaboration, security, and governance. PowerShell enables admins to assign, remove, and update user roles in Power BI workspaces efficiently.

This guide provides a step-by-step approach to assigning users to Power BI workspaces using PowerShell.


Step 1: Prerequisites

1. Install the Power BI Management Module

Ensure the Microsoft Power BI Management module is installed:

Install-Module MicrosoftPowerBIMgmt -Scope CurrentUser -Force

Power BI PowerShell module installed!

2. Connect to Power BI Service

Authenticate using an admin account:

Connect-PowerBIServiceAccount

Authenticated successfully!


Step 2: List Available Power BI Workspaces

To assign users, first identify the workspace:

Get-PowerBIWorkspace -Scope Organization | Select-Object Id, Name

Power BI workspaces listed!


Step 3: Assign a User to a Workspace

To assign a user, use the Add-PowerBIWorkspaceUser command.

1. Assign a User as a Viewer

Add-PowerBIWorkspaceUser -Id "<Workspace_ID>" -UserPrincipalName "user@yourdomain.com" -AccessRight Viewer

User added as Viewer!

2. Assign a User as a Member

Add-PowerBIWorkspaceUser -Id "<Workspace_ID>" -UserPrincipalName "user@yourdomain.com" -AccessRight Member

User added as Member!

3. Assign a User as an Admin

Add-PowerBIWorkspaceUser -Id "<Workspace_ID>" -UserPrincipalName "user@yourdomain.com" -AccessRight Admin

User added as Admin!


Step 4: Assign Multiple Users from a CSV File

If you need to bulk assign users, create a CSV file (Users.csv):

csvCopyEditUserPrincipalName,AccessRight
user1@yourdomain.com,Member
user2@yourdomain.com,Admin
user3@yourdomain.com,Viewer

Then, use PowerShell to assign users:

$workspaceId = "<Workspace_ID>"
$users = Import-Csv "C:\Path\To\Users.csv"

foreach ($user in $users) {
Add-PowerBIWorkspaceUser -Id $workspaceId -UserPrincipalName $user.UserPrincipalName -AccessRight $user.AccessRight
}

Write-Host " Users assigned successfully!"

Bulk user assignment completed!


Step 5: Remove a User from a Workspace

To remove a user:

Remove-PowerBIWorkspaceUser -Id "<Workspace_ID>" -UserPrincipalName "user@yourdomain.com"

User removed!


Step 6: Verify Assigned Users

To list all users in a workspace:

Get-PowerBIWorkspaceUser -Id "<Workspace_ID>"

Workspace users retrieved!


Step 7: Automate Workspace User Management

Create a PowerShell script Manage_PowerBI_Workspaces.ps1:

# Connect to Power BI
Connect-PowerBIServiceAccount

# Import users from CSV
$workspaceId = "<Workspace_ID>"
$users = Import-Csv "C:\Path\To\Users.csv"

# Assign users
foreach ($user in $users) {
Add-PowerBIWorkspaceUser -Id $workspaceId -UserPrincipalName $user.UserPrincipalName -AccessRight $user.AccessRight
}

Write-Host " Users assigned successfully!"

Schedule it via Task Scheduler to run at regular intervals.

Automated user management enabled!

Leave a Reply

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