Forum Discussion
How to extract RLS (roles, filters...)from Power BI Service datasets step-by-step(REST API/XMLA/DMV?
Hi,
You can achieve this, but you need to combine Power BI REST API (for inventory) and XMLA endpoint + DMVs (for RLS metadata). Below is a practical step-by-step approach that I’ve used successfully.
✅ Step 1 – List Workspaces (REST API)
Call:
GET https://api.powerbi.com/v1.0/myorg/groups
Required scope:
Workspace.Read.All (or ReadWrite)
This returns all workspaces the principal has access to.
✅ Step 2 – List Datasets per Workspace
For each workspace:
GET https://api.powerbi.com/v1.0/myorg/groups/{groupId}/datasetsRequired scope:
Dataset.Read.All
At this point you have:
Workspace ID
Dataset ID
Dataset Name
⚠️ Important Requirement
To extract RLS roles and filters, the dataset must:
Be in Premium / Fabric capacity
Have XMLA endpoint enabled (Read or Read/Write)
Otherwise DMVs will not work.
✅ Step 3 – Connect to XMLA Endpoint
XMLA endpoint format:
powerbi://api.powerbi.com/v1.0/myorg/{WorkspaceName}You can connect using:
SSMS
Tabular Editor
PowerShell
Python (via ADOMD)
C# (Microsoft.AnalysisServices.Tabular)
Authentication:
User (Azure AD)
OR Service Principal (must be enabled in tenant settings)
Tenant setting required:
“Allow service principals to use Power BI APIs”
“Allow XMLA endpoints and Analyze in Excel with on-prem datasets”
✅ Step 4 – DMV Queries for RLS
Once connected to the dataset database, run:
🔹 List Roles
SELECT * FROM $SYSTEM.TMSCHEMA_ROLES
🔹 Role Members
SELECT * FROM $SYSTEM.TMSCHEMA_ROLE_MEMBERSHIPS
🔹 Table-Level Filters (RLS expressions)
SELECT * FROM $SYSTEM.TMSCHEMA_TABLE_PERMISSIONS
The column FilterExpression contains the DAX filter definition.
✅ Optional – Python Example (Simplified Concept)
Using pyadomd:
from pyadomd import Pyadomd
conn_str = "Provider=MSOLAP;Data Source=powerbi://api.powerbi.com/v1.0/myorg/WorkspaceName;Initial Catalog=DatasetName;"
with Pyadomd(conn_str) as conn:
with conn.cursor().execute("SELECT * FROM $SYSTEM.TMSCHEMA_ROLES") as cur:
print(cur.fetchall())(You must authenticate beforehand using Azure AD token.)
🔐 Service Principal Requirements
If using SPN:
Register App in Entra ID
Create Client Secret
Add API permissions:
Dataset.Read.All
Workspace.Read.All
Grant Admin Consent
Enable SPN usage in Power BI Tenant Settings
Add SPN as:
Workspace Member/Admin
Or Dataset Admin
📊 Final Architecture
REST API → Build inventory table of:
Workspace
Dataset
Loop datasets → XMLA connection
Execute DMV queries
Store results in:
SQL table
Dataflow
Lakehouse
or Power BI model
🚀 Summary
Requirement Needed?
| Premium/Fabric capacity | ✅ Yes |
| XMLA endpoint enabled | ✅ Yes |
| REST API | ✅ For inventory |
| DMVs | ✅ For roles/members/filters |
| Service Principal | Optional but recommended for automation |
This approach gives you:
Workspace → Dataset → Role → Members → Filter Expression
If helpful, I can also share a fully automated PowerShell or end-to-end architecture pattern.
Hope this helps 🙂
Thanks again — this was very helpful.
We’ve confirmed:
Premium/Fabric capacity is available
XMLA endpoint is enabled
I understand the overall architecture now:
Use REST API to inventory workspaces and datasets
Loop datasets and connect via XMLA
Query:
$SYSTEM.TMSCHEMA_ROLES
$SYSTEM.TMSCHEMA_ROLE_MEMBERSHIPS
$SYSTEM.TMSCHEMA_TABLE_PERMISSIONS
Before implementing automation, I’d appreciate seeing your PowerShell (or Python) end-to-end pattern for:
Service principal authentication
XMLA connection
Executing DMV queries programmatically
Thanks again!
- v-nmadadi-msft6 months agoCommunity Support
Hi matesum1234 ,
Thanks for reaching out to the Microsoft Fabric Community forum.
Install Power BI module usingInstall-Module -Name MicrosoftPowerBIMgmt -Scope CurrentUser -Force
Provide information related to Service principal$AppId = "examplexxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" $TenantId = "examplexxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" $ClientSecret = "ClientSecretHere"
Create Secure Strings$SecurePassword = ConvertTo-SecureString $ClientSecret -Force -AsPlainText $Credential = New-Object Management.Automation.PSCredential($AppId, $SecurePassword)
Connect to the Power BI service using these commandsConnect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
get the list of workspaces and list of reports using these commandsGet-PowerBIWorkspace Get-PowerBIReport
To connect to XMLA Endpoint:$tokenResponse = Invoke-RestMethod ` -Method Post ` -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" ` -Body $body $accessToken = $tokenResponse.access_tokenAdd-Type -AssemblyName "Microsoft.AnalysisServices.Tabular" $workspaceName = "your workspace name" $xmlaEndpoint = "powerbi://api.powerbi.com/v1.0/myorg/$workspaceName" $server = New-Object Microsoft.AnalysisServices.Tabular.Server # Connection string with access token $connectionString = "DataSource=$xmlaEndpoint;Password=$accessToken;User ID=app:$clientId@$tenantId" $server.Connect($connectionString)
List database using$server.Databases | Select NameEach database = one semantic model (dataset).
Run DMV queries using$datasetName = "Your Dataset Name" $database = $server.Databases[$datasetName] $query = "SELECT * FROM `$SYSTEM.TMSCHEMA_ROLES" $result = $database.Model.ExecuteDaxQuery($query) $result.Tables[0]
Reference:
Working with PowerShell in Power BI | Microsoft Power BI Blog | Microsoft Power BI
Connect-PowerBIServiceAccount (MicrosoftPowerBIMgmt.Profile) | Microsoft Learn
I hope this information helps. Please do let us know if you have any further queries.
Thank you- Anonymous6 months agoNot applicable
Do you know if that error is happening because I am not the creator of the semantic model? I need a solution to extract the RLS information without being the creator. AdomdErrorResponseException: User '<my_email>' needs to be an administrator to read the metadata of the database '6b4e132c-...'
- v-nmadadi-msft6 months agoCommunity Support
Hi matesum1234 ,
The error is not related to being the creator of the semantic model. XMLA metadata queries such as TMSCHEMA_ROLES require database-level administrative permissions. To extract RLS definitions, you must be a Workspace Admin. Member or Build permissions are not sufficient to read model metadata via XMLA.
I hope this information helps. Please do let us know if you have any further queries.
Thank you