Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Removing multiple users form the power bi workspace using powershell script

Hi All,

 

I have a list of workspaces and user names in one csv file and i need to remove that individual users from the workspace who are in that excel file. Remove in Power BI service taking time. So by using that CSV file i need to remove multiple users using PowerShell script. If it is possible please share the sctipt. Thanks in advance!

3 Replies

  • tackytechtom's avatar
    tackytechtom
    Most Valuable Professional

    Hi  Anonymous, 

     

    Yes, it is possible to use a PowerShell script to remove multiple users from a Power BI workspace. To do this, you can use the Remove-PowerBIWorkspaceUser cmdlet, which is part of the Power BI PowerShell module.

    Here is an example of a script that you can use to remove multiple users from a PowerBI workspace using a CSV file:

     

    # Import the Power BI module
    Import-Module -Name MicrosoftPowerBIMgmt # Connect to Power BI Connect-PowerBI # Set the path to the CSV file containing the list of workspaces and user names $csvFilePath = "C:\path\to\file.csv" # Read the CSV file into a variable $users = Import-Csv -Path $csvFilePath # Loop through the rows in the CSV file foreach ($user in $users) { # Get the workspace ID and user name from the current row $workspaceId = $user.WorkspaceId $userName = $user.UserName # Remove the user from the workspace Remove-PowerBIWorkspaceUser -WorkspaceId $workspaceId -UserName $userName }

     

    In this script, the CSV file is assumed to have two columns: "WorkspaceId" and "UserName". The script reads the CSV file into a variable, and then loops through the rows in the file, extracting the workspace ID and user name for each row. The Remove-PowerBIWorkspaceUser cmdlet is then called for each row, passing in the workspace ID and user name as arguments, to remove the user from the workspace.

     

    Let me know if this works 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/