Forum Discussion
Permission Change on Power BI workspaces
- 1 year ago
I already provided the details. Remove the admins, add the contributors.
- 1 year ago
Hi NBK52
To update Power BI workspace permissions using PowerShell, first, import the Power BI module and authenticate using Login-PowerBI. Then, load the CSV file containing workspace IDs and names. For each workspace, retrieve the list of users with "Admin" access using Get-PowerBIWorkspace. Loop through these users, remove their "Admin" role using Remove-PowerBIWorkspaceUser, and assign them "Contributor" access using Add-PowerBIWorkspaceUser. Ensure you have Power BI admin permissions to execute these changes. The script can be modified to exclude certain users or log changes for tracking. Additionally, automation can be achieved using a service principal instead of interactive login. Always review permissions before running the script to prevent accidental access modifications.
I have used below script for the same requirement and have the data in excel like below
WorkspaceId,WorkspaceName
<workspace_id_1>,<workspace_name_1>
<workspace_id_2>,<workspace_name_2>
# Import the Power BI module
Import-Module MicrosoftPowerBIMgmt
# Authenticate to Power BI
Login-PowerBI
# Load the CSV file containing workspace IDs and names
$workspaces = Import-Csv -Path "C:\Temp\Myworkspaces.csv"
# Loop through each workspace
foreach ($workspace in $workspaces) {
$workspaceId = $workspace.WorkspaceId
$workspaceName = $workspace.WorkspaceName
# Retrieve the list of users with "Admin" access
$adminUsers = Get-PowerBIWorkspace -Id $workspaceId -Scope Organization |
Get-PowerBIWorkspaceUser |
Where-Object { $_.AccessRight -eq 'Admin' }
# Loop through each admin user
foreach ($adminUser in $adminUsers) {
$userEmail = $adminUser.EmailAddress
# Remove "Admin" role
Remove-PowerBIWorkspaceUser -Id $workspaceId -User PrincipalName $userEmail -Confirm:$false
# Assign "Contributor" role
Add-PowerBIWorkspaceUser -Id $workspaceId -User PrincipalName $userEmail -AccessRight Contributor
}
}
# Logout from Power BI
Logout-PowerBI
But got this below error. Please sugest.
Get-PowerBIWorkspaceUser : The term 'Get-PowerBIWorkspaceUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
Users, not User. Iterate over the list.