Forum Discussion

Gow_tham's avatar
Gow_tham
Frequent Visitor
1 year ago

How can I programmatically add or remove users for a Power BI dataset, given the following scenario?

I'm overhauling the RLS setup for master datasets in my organization, which has around 1000 active users. We have 9 fixed security roles, and users move between these roles monthly. While we can use existing security groups for some roles, we don't have permission to create new security groups for others. This forces us to manually add or remove members in the Power BI Service.
Creating new security groups is out of scope.

Is there a way to automate this process using APIs or PowerShell?

4 Replies

  • Gow_tham to my knowledge there are no Rest API's or XMLA approaches to add users / members to a RLS role. It is possible to create Roles dynamically using semantic-link python library but the members cannot be added to or removed form the roles created. The best option is to have a security group for each role, but you stated it is out of scope in your current project. Not sure about the powershell route.

     

    Did I answer your question. If yes, please accept my post as a solution.

     

    Thanks,

    Jai

    • Gow_tham's avatar
      Gow_tham
      Frequent Visitor


      Thanks Jai-Rathinavel 
      After checking out the community forums and talking to some MVPs, it looks like there aren't any REST APIs or PowerShell cmdlets to add users to a role programmatically (like you said). I've added this idea to the PowerBI Ideas forum. Meanwhile, I'm working on convincing my IT team/administrators to use security groups for different roles in the dataset and manage access that way. I have a PowerShell script that can add users to a security group from a CSV file. If you know any other easy ways to add users to a security group, let me know!

      Cheers, 
      Gowtham

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Gow_tham 

    Maybe you can use PowerShell to manage users in Power BI. Here’s a simplified example:

    # Install the Power BI module
    Install-Module -Name MicrosoftPowerBIMgmt
    
    # Connect to Power BI
    Connect-PowerBIServiceAccount
    
    # Add a user to a role
    Add-PowerBIRoleMember -GroupId $groupId -DatasetId $datasetId -RoleId $roleId -UserPrincipalName $userEmail
    
    # Remove a user from a role
    Remove-PowerBIRoleMember -GroupId $groupId -DatasetId $datasetId -RoleId $roleId -UserPrincipalName $userEmail

     

     You can check the following links:

    Power BI Cmdlets reference | Microsoft Learn

     

    PowerShell cmdlets, REST APIs, and .NET Client libraries for administrators - Power BI | Microsoft Learn

     

    How to Get Your Question Answered Quickly

    Best Regards

    Yongkang Hua

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Gow_tham's avatar
      Gow_tham
      Frequent Visitor

      Hello Anonymous ,

      Upon testing, I received an error stating that there is no PowerShell cmdlet named AddPowerBIRoleMember. I searched for this cmdlet in the PowerShell reference links but couldn't find any reference to it. 

      Note: I have installed the 
      MicrosoftPowerBIMgmt PowerShell module.