Problem Statement:
You need to retrieve the list of users who have access to a specific dataset in Power BI. PowerBi UI doesn't allow to export. The goal is to gather this information using PowerShell scripting and export the results to a CSV file.
Solution-
Here's a step-by-step guide on how to accomplish this:
Begin by launching a Windows PowerShell session.
Verify Power BI Cmdlets Installation Before starting, it's essential to verify if the Power BI cmdlets are already installed on your machine. Open an elevated Windows PowerShell session and run the following command:
Get-Module -Name MicrosoftPowerBIMgmt -ListAvailable
If the cmdlets are listed, you already have them installed. If not, install using below code-
Install-Module -Name MicrosoftPowerBIMgmt
3. Next, you'll need to log in to Power BI. Execute the below command to do so:
Login-PowerBI
4. Retrieve Dataset ID -Open your Power BI workspace in a web browser. Go to dataset and Examine the URL and locate the long GUID that appears after "powerbi.com/groups/WorkspaceId/datasets/". This GUID represents the dataset ID. Copy this value and run below.
$datasetId ='CopiedDatasetId'
5. Get access token using below code-
$accessToken = (Get-PowerBIAccessToken).Authorization
6. Get header for further steps-
$headers = @{
'Content-Type' = 'application/json'
'Authorization' = $accessToken
}
7. Create Api Url
8. Get Api response using below code
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method Get
9. Create local path variable.
$csvFilePath = "your local path"
10. Use below code to get users finally stored in path mentioned.
$response.value | Export-Csv -Path $csvFilePath -NoTypeInformation
Conclusion:
This PowerShell script retrieves the list of users who have accessed a specific Power BI dataset. It starts by obtaining the necessary IDs and access token, then constructs the API URL and sends a GET request to Power BI REST API. The response, containing user information, is exported to a CSV file for further analysis or reporting.
There is further scope to get across all the workspaces without manually passing. Let me know in comment i will comeup with another post for that.
Hi Naveen, 1 request can you plz create similar content to get list of reports where a particular person has access
Thanks Naveen, followed step by step. worked for me