Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi All,
I need a PowerShell script to change the admin access of the workspace admins to Contributer.
Who all are having the Admin access to worksapce need to be changed to Contributer. I can not do manually as I have lot of workspaces.
Could you please assist on this.
Solved! Go to Solution.
Hi @NBK52
Can you try this:
# Import Power BI Module
Import-Module MicrosoftPowerBIMgmt
# Authenticate to Power BI Service
Connect-PowerBIServiceAccount
# Retrieve all workspaces
$workspaces = Get-PowerBIWorkspace -All -Scope Organization
# Loop through each workspace
foreach ($workspace in $workspaces) {
Write-Host "Processing Workspace: $($workspace.Name)" -ForegroundColor Yellow
# Get all admins of the workspace
$admins = Get-PowerBIWorkspaceUser -Id $workspace.Id | Where-Object { $_.AccessRight -eq "Admin" }
foreach ($admin in $admins) {
Write-Host "Changing Admin ($($admin.UserPrincipalName)) to Contributor" -ForegroundColor Cyan
# Remove the admin access
Remove-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $admin.UserPrincipalName
# Add the user back as a Contributor
Add-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $admin.UserPrincipalName -AccessRight Contributor
}
}
Write-Host "All workspace admins have been updated to Contributor!" -ForegroundColor Green
Hello @NBK52 ,
Thanks for reaching out to the Microsoft fabric community forum.
It looks like
I would also take a moment to personally thank @Poojara_D12 , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
Based on his response, it is indeed your task to change the admin access of workspace admins to contributor. The code involves all workspace IDs. Additionally, I wanted to mention that we can also use specific workspace IDs for changing the admin to contributor. Please use the following code to achieve this:
Import-Module MicrosoftPowerBIMgmt
Connect-PowerBIServiceAccount
Get-PowerBIWorkspace
$workspaceId = "<Your-Workspace-ID>"
$admins = @("<Admin-Email1>", "<Admin-Email2>")
foreach ($admin in $admins)
{
Remove-PowerBIWorkspaceUser -Id $workspaceId -UserEmailAddress $admin
Add-PowerBIWorkspaceUser -Id $workspaceId -UserEmailAddress $admin -AccessRight Contributor
}
For your better understanding, I am including a documentation link. Please refer to it:
Add-PowerBIWorkspaceUser (MicrosoftPowerBIMgmt.Workspaces) | Microsoft Learn
I hope my suggestions give you good ideas, if you need any further assistance, feel free to reach out.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thank you.
Thank you for providing..Can this be done like changing permissions from admin to contributor for the Workspaces read from a CSV as we have lot of workspaces and we need to do some batch wise.
Hi @NBK52
Can you try this:
# Import Power BI Module
Import-Module MicrosoftPowerBIMgmt
# Authenticate to Power BI Service
Connect-PowerBIServiceAccount
# Retrieve all workspaces
$workspaces = Get-PowerBIWorkspace -All -Scope Organization
# Loop through each workspace
foreach ($workspace in $workspaces) {
Write-Host "Processing Workspace: $($workspace.Name)" -ForegroundColor Yellow
# Get all admins of the workspace
$admins = Get-PowerBIWorkspaceUser -Id $workspace.Id | Where-Object { $_.AccessRight -eq "Admin" }
foreach ($admin in $admins) {
Write-Host "Changing Admin ($($admin.UserPrincipalName)) to Contributor" -ForegroundColor Cyan
# Remove the admin access
Remove-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $admin.UserPrincipalName
# Add the user back as a Contributor
Add-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $admin.UserPrincipalName -AccessRight Contributor
}
}
Write-Host "All workspace admins have been updated to Contributor!" -ForegroundColor Green
Thank you for providing!! and in the provided script how can we exclude user personal workspaces..But I need do for testing for some of specific workspaces before doing it all..can this be done using workspace IDs or any..changing the admin to contributer on some of specific workspaces
User | Count |
---|---|
48 | |
31 | |
27 | |
26 | |
26 |
User | Count |
---|---|
60 | |
56 | |
36 | |
32 | |
28 |