cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kimlaurits
Regular Visitor

Add-PowerBIWorkspaceUser - adding group to Workspace

Hi,

I am trying to automate different PowerBI tasks using a service principal.

I can create new PowerBI Workspaces and the service principal is an admin on the Workspace.

Afterwards I would like to add a synchronised AD group as contributor, with the following:
Add-PowerBIWorkspaceUser -Id <ID of PowerBI Workspace> -PrincipalType Group -AccessRight Contributor -Identifier <Object Id of AD group>

I get the error:

Add-PowerBIWorkspaceUser : Operation returned an invalid status code 'NotFound'

 

Am I missing something - or doing it wrong?

 

 

 

1 ACCEPTED SOLUTION

HI , 
Below worked like a charm : 

mahakrathore_0-1654173532730.png

 

Add-PowerBIWorkspaceUser -Scope Organization -Id <workspaceid> -UserEmailAddress mahak@xxxxxxxxx.com -AccessRight Admin
Ensure: You have Admin Rights to add the user. I tested it just now my user from which running API has Admin Rights on the workspace and its Premium ( to be considered if you are adding free user ) 

Waiting for update 🙂 

CHeers
Mahak


 

View solution in original post

10 REPLIES 10
mahakrathore
Helper I
Helper I

Did you tried : 

Add-PowerBIWorkspaceUser -Scope Individual -Id myWorkSpaceIDasString -Identifier myIdentifierAsString -AccessRight Admin -PrincipalType Group

Regards,Mahak 

Also, there is a very nice blog/code available for Automation: https://github.com/microsoft/powerbi-powershell/blob/master/src/Modules/Workspaces/Commands.Workspac... which can help more. Tried and Tested.

I tried it, but I get the same error:

Add-PowerBIWorkspaceUser : Operation returned an invalid status code 'NotFound'

 

It works when I add a user to a Workspace:

Add-PowerBIWorkspaceUser -Id <Workspace Id> -AccessRight Contributor -Identifier <User UPN> -PrincipalType User

HI , 
Below worked like a charm : 

mahakrathore_0-1654173532730.png

 

Add-PowerBIWorkspaceUser -Scope Organization -Id <workspaceid> -UserEmailAddress mahak@xxxxxxxxx.com -AccessRight Admin
Ensure: You have Admin Rights to add the user. I tested it just now my user from which running API has Admin Rights on the workspace and its Premium ( to be considered if you are adding free user ) 

Waiting for update 🙂 

CHeers
Mahak


 

Yes - the same works here, when adding a user.

 

But unfortunately it doesn't work when adding a AD group.

Did you tried the latest code I posted?

Login-PowerBI

#Using AD Security group

$Body = @{
identifier= “add your Odject ID here” #Object ID for the Security group
groupUserAccessRight= “Admin” #Permission for the group to the Workspace
principalType= “Group” #The type of Principal(App, Group, User)
}

$BodyJSON=$Body | ConvertTo-Json
Invoke-PowerBIRestMethod -Method post -Url “/groups/Add your group Id here/users” -Body $BodyJSON #Workspace ID

 

Can you trythis too. 

 

This worked for me to add my Functional Email Group to the same workspace.


Cheers 
Mahak

@kimlaurits 

mahakrathore_0-1654174373605.png

#Using AD Security group

$Body = @{
identifier= “<groupidfromAzureAD>” #Object ID for the Security group
groupUserAccessRight= “Admin” #Permission for the group to the Workspace
principalType= “Group” #The type of Principal(App, Group, User)
}

$BodyJSON=$Body | ConvertTo-Json
Invoke-PowerBIRestMethod -Method post -Url “/groups/<workspaceIDpastehere>/users” -Body $BodyJSON #Workspace ID


Cheers
Mahak

 

Yes, that seems to work well.

 

Awesome. Could you please mark it as Solution Provided i.e. my answer. 

Cheers

Mahak

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors