Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I tried to run the Powershell script below to add a user to all active workspaces, but the script fails returning the "unauthorized" status code. I am running the script having signed into the Power Bi Management modules as my Fabric Admin account (after signign in with Connect-PowerBIServiceAccount).
The script successully gets all relevant workspaces, it just doesn't add the user.
The fabric administrator doesn't have access to the workspaces, but having the global Fabric Administrator role it can add users to workspaces in the admin portal (but I need an automated approach)
$workspaces = Get-PowerBIWorkspace -Scope Organization | Where {($_.State -eq "Active") -and ($_.Type -eq "Workspace")}
##$workspaces
$user = "Username@domain.co.uk"
foreach($workspace in $workspaces)
{
Write-Host "Adding User to : " $workspace.Name
try
{
Add-PowerBIWorkspaceUser -Id $workspace.Id -UserPrincipalName $user -AccessRight Contributor
}
catch
{
Write-Host "Message: [$($_.Exception.Message)"] -ForegroundColor Red
}
}
What do I need to do to run a script like this; I need it to add a specific user to all workspaces that are active / of the type "workspace" as per my filters. There is no one account that has access, so I believe I need to run it as a fabric administrator
Solved! Go to Solution.
Hi. I work a lot with Power Bi Rest API, not specifically with powershell. However, I can deduce that it won't work. Being Fabric Administration only means you can use the Admin rest api or in this case the MicrosoftPowerBiMgmt.Admin. That would be the benefit. All other requests outside the admin work for any user. The way they work is that it let's the account opperate what the requests if they really have access to the resources. That means the MicrosoftPowerBiMgmt.Workspaces will only work with the workspaces the account logged in can actually see. If you want to add users to a workspace as Fabric Administrator, you should try this api request that it's under admin category: https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-add-user-as-admin
That one should work without unauthorized.
I hope that helps,
Happy to help!
Thank you for reaching out to the Microsoft Fabric Forum Community.
@ibarrau Thanks for your inputs.
I hope the information provided by users was helpful. If you still have questions, please don't hesitate to reach out to the community.
I wanted to check if you had the opportunity to review the information provided by users. Please feel free to contact us if you have any further questions.
Hope everything’s going smoothly on your end. I wanted to check if the issue got sorted. if you have any other issues please reach community.
Hi. I work a lot with Power Bi Rest API, not specifically with powershell. However, I can deduce that it won't work. Being Fabric Administration only means you can use the Admin rest api or in this case the MicrosoftPowerBiMgmt.Admin. That would be the benefit. All other requests outside the admin work for any user. The way they work is that it let's the account opperate what the requests if they really have access to the resources. That means the MicrosoftPowerBiMgmt.Workspaces will only work with the workspaces the account logged in can actually see. If you want to add users to a workspace as Fabric Administrator, you should try this api request that it's under admin category: https://learn.microsoft.com/en-us/rest/api/power-bi/admin/groups-add-user-as-admin
That one should work without unauthorized.
I hope that helps,
Happy to help!
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!