Forum Discussion

NBK52's avatar
NBK52
Helper I
1 year ago
Solved

Permission Change on Power BI workspaces

Hi All,

 

We have a list of workspaces along with workspaces ids in CSV file. Whoever is Admin access to these all workspaces need to be converted to contribute permission though PowerShell script. 

 

Kindly suggest. let me know if any details are required.

 Thanks.

  • I already provided the details. Remove the admins, add the contributors.

  • 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.

     

12 Replies

    • NBK52's avatar
      NBK52
      Helper I

      Yes, That woud leave without Admins..Workspace Admins already there for each Workflow but we need to change who are having admin permission to workspaces to contribute.

       

      We have list of workspaces and workspaces ids in CSV file, Now we want to change whoever having the admin permission to those users to contribute through PowerShell script.

       

      We need to do it in bulk hence required PowerShell script that read data from CSV file and change the permission

       

      Can this be done?. Let us know if any details required

      • lbendlin's avatar
        lbendlin
        Super User

        I already provided the details. Remove the admins, add the contributors.

  • 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.

     

    • NBK52's avatar
      NBK52
      Helper I

      Hi Poojara_D12 , lbendlin 

      Can this blow script can be modified to change the workspace admins to contriburer from the list of CSV files. I am new to PowerShell script..need your assistance.

       

      I have the data in excel like below 

      WorkspaceId,WorkspaceName
      <workspace_id_1>,<workspace_name_1>
      <workspace_id_2>,<workspace_name_2>

       

      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

      }

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi NBK52  ,
    Thanks for reaching out to the Microsoft fabric community forum.
    You can use this following PowerShell script to loop through the CSV file like you want to get the workspace id’s

     

    $csvfile = Import-CSV -Path " CSV file path "
    foreach( $row in $csvfile){ Write-Output "workspace_id: $($row.workspace_id)"}

     


    Once you retrieve the workspace ID's

    As mentioned by lbendlin  , Poojara_D12  please follow the document to change the permission of admins to contributor. 


    If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS.
    Thanks and Regards

  • 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.

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi NBK52 

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. If you've found another step that worked, feel free to share it and mark it as the solution. This will help others to gain additional insights and benefit from your experience and will be helpful for other community members who have similar problems to solve it faster.

    Thank you.

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi NBK52,

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


    Thank you.

  • v-nmadadi-msft's avatar
    v-nmadadi-msft
    Community Support

    Hi NBK52 ,

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the community members for the issue worked. If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

     

    Thanks and regards