Guidance for using fab to programmatically manage Fabric & Power BI service
uv tool install ms-fabric-cli (get uv via winget install uv or brew install uv)fab current: check the installed version against the latest ms-fabric-cli release and upgrade with uv tool upgrade ms-fabric-cli unless the user has pinned a specific version. Discover commands and flags with fab --help and fab <command> --help rather than hard-coding behavior; the CLI surface changes regularly[!IMPORTANT] Any time you encounter errors, user preferences or learnings when using the Fabric cli, ALWAYS note these down in the user memory rules, i.e.
.claude/rules/fabric-cli.mdfor future improvement. This is ONLY for generic learnings and not for item- or task-specific learnings.
fab run check that it is up to date to the latest version (upgrade with uv tool upgrade ms-fabric-cli unless the user has pinned a version) and run fab auth status; If user isn't authenticated, ask them to run fab auth login
fab --help and fab <command> --help the first time you use a command to understand its syntaxfab
fab ls or fab exists before proceedingfab export does not create intermediate directories; mkdir -p the output path first or the command fails with [InvalidPath]
-f (force) for non-interactive useThe fab CLI prompts for confirmation, so you you must always append -f to prevent this UNLESS sensitivity labels are enabled, in which case you must ask the user. Do this for the commands:
fab get -q "definition" ; sensitivity label confirmationfab export ; sensitivity label confirmationfab import ; overwrite confirmationfab cp / fab cp -r ; overwrite and sensitivity label confirmationfab rm ; delete confirmationfab assign / fab unassign ; capacity/domain assignment confirmationfab mv ; rename/move confirmationYou must read and understand the common list of operations with simple examples
fab --help and fab auth status
fab exists "spaceparts-dev.Workspace/spaceparts-otc-full.SemanticModel"
fab find 'sales' -P type=Report -l (substring on name, description, workspace; -P type= to filter, -l for ids; -q '<jmespath>' for client-side filter/projection). For governance workflows that need last visit / last refresh / owner / storage mode / capacity SKU, use scripts/search_across_workspaces.py; see workspaces.md for the delta.fab ls
fab ls "Workspace Name.Workspace"
fab desc to get itemTypesfab desc .<ItemType> for commands i.e. fab desc .SemanticModel
fab get "spaceparts-dev.Workspace/spaceparts-otc-full.SemanticModel" -q "definition" -f
fab get "ws.Workspace/Model.SemanticModel" -q "definition" -f | rga -i "Sales Amount"
fab ls "ws.Workspace/LH.Lakehouse/Files"
fab ls "ws.Workspace/LH.Lakehouse/Tables"
fab table schema "ws.Workspace/LH.Lakehouse/Tables/gold/orders"
fab api / duckdb / sqlcmd; they resolve IDs, hosts, and auth for you):
python3 scripts/execute_dax.py "ws.Workspace/Model.SemanticModel" -q "EVALUATE TOPN(10, 'Orders')"
python3 scripts/query_lakehouse_duckdb.py "ws.Workspace/LH.Lakehouse" -q "SELECT * FROM tbl LIMIT 10" -t gold.orders
sqlcmd + az session): python3 scripts/query_sql_endpoint.py "ws.Workspace/LH.Lakehouse" -q "SELECT TOP 10 * FROM dbo.orders"
fab set "ws.Workspace/Item.Notebook" -q displayName -i "New Name" or fab set "ws.Workspace" -q description -i "Production environment"
fab acl ls "ws.Workspace/Model.SemanticModel" then fab acl set "ws.Workspace/Model.SemanticModel" -I user@contoso.com -R Read
fab acl ls "ws.Workspace" then fab acl set "ws.Workspace" -I user@contoso.com -R Member
fab import "ws.Workspace/New.Notebook" -i ./local-path/Nb.Notebook -f
fab export "ws.Workspace/Nb.Notebook" -o ./backup -f (always mkdir -p ./backup first)fab cp "dev.Workspace/Item.Notebook" "prod.Workspace" -f or fab mv "ws.Workspace/Old.Notebook" "ws.Workspace/New.Notebook" -f
fab open "spaceparts-dev.SpaceParts/Amazing Report.Report"
fab api -A powerbi "groups/<ws-id>/datasets/<model-id>/refreshes" -X post -i '{"type":"Full"}' or fab api "workspaces/<ws-id>/items"
scripts/query_sql_endpoint.py (reuses az login via ActiveDirectoryAzCli; full walkthrough in querying-data.md)az login --service-principal -u <appId> -t <tenantId> --password "$(az keyvault secret show --vault-name <vault> --name <secret> --query value -o tsv)" ; command substitution pipes the secret directly into the child process arg list, never stdout, a file, or a named shell variableFor information about any concepts related to Power BI or Fabric you must search or fetch via the microsoft-learn MCP server (or the pbi-search CLI as an alternative) and ask the user questions with the AskUserQuestion tool; NEVER guess or make assumptions.
Pay special attention to each of the following areas when using the Fabric CLI
Fabric uses filesystem-like paths with type extensions:
"WorkspaceName.Workspace/ItemName.ItemType"
You must quote paths with spaces and punctuation:
"Workspace Name.Workspace/Semantic Model Name.SemanticModel"
For lakehouses this is extended into files and tables:
WorkspaceName.Workspace/LakehouseName.Lakehouse/Files/FileName.extension or /WorkspaceName.Workspace/LakehouseName.Lakehouse/Tables/TableName
For Fabric capacities you have to use fab ls .capacities
Examples:
"Production Workspace.Workspace/Sales Report.Report"
Data.Workspace/MainLH.Lakehouse/Files/data.csv
Data.Workspace/MainLH.Lakehouse/Tables/dbo/customers
.Workspace - Workspaces.SemanticModel - Power BI datasets.Report - Power BI reports.Notebook - Fabric notebooks.DataPipeline - Data pipelines.Lakehouse / .Warehouse/ .SQLDatabase - Data artifacts.SparkJobDefinition - Spark jobs.AISkill - Fabric Data Agents.MirroredDatabase / .MirroredWarehouse - Mirrored databases.Environment - Spark environments.UserDataFunction - User data functionsFull list: You must use fab desc or fab desc .<ItemType> to check syntax and types if the user asks about an item type not listed above.
Filter and transform JSON responses with -q:
# Get single field
-q "id"
-q "displayName"
# Get nested field
-q "properties.sqlEndpointProperties"
-q "definition.parts[0]"
# Filter arrays
-q "value[?type=='Lakehouse']"
-q "value[?contains(name, 'prod')]"
# Get first element
-q "value[0]"
-q "definition.parts[?path=='model.tmdl'] | [0]"
fab apifab has an api escape hatch that lets you use any API even if it doesn't have primary commands.
To use fab api you need item IDs. Extract them like this:
WS_ID=$(fab get "ws.Workspace" -q "id" | tr -d '"')
MODEL_ID=$(fab get "ws.Workspace/Model.SemanticModel" -q "id" | tr -d '"')
# Then use in API calls
fab api -A powerbi "groups/$WS_ID/datasets/$MODEL_ID/refreshes" -X post -i '{"type":"Full"}'
Don't use admin commands or APIs if the user doesn't have Admin access. Here's some examples:
# Find semantic models by name (cross-workspace)
fab api "admin/items" -P "type=SemanticModel" -q "itemEntities[?contains(name, 'Sales')]"
# Find all notebooks
fab api "admin/items" -P "type=Notebook" -q "itemEntities[].{name:name,workspace:workspaceId}"
# Find all lakehouses
fab api "admin/items" -P "type=Lakehouse"
# Common types: SemanticModel, Report, Notebook, Lakehouse, Warehouse, DataPipeline, Ontology
For full admin API reference (cross-workspace discovery, tenant settings read/update, capacity/domain/workspace overrides, activity events): admin.md
# Show response headers
fab api workspaces --show_headers
# Verbose output
fab get "Production.Workspace/Item" -v
# Save responses for debugging
fab api workspaces -o /tmp/workspaces.json
These are the most common workflows you'll encounter in Fabric
| Command | Purpose | Example |
|---|---|---|
fab ls |
List workspaces / items | fab ls "Sales.Workspace" -l |
fab exists |
Check if a path exists | fab exists "Sales.Workspace/Model.SemanticModel" |
fab get |
Get item details | fab get "Sales.Workspace" -q "id" |
fab desc |
Supported commands per type | fab desc .SemanticModel |
Flags:
-l (long listing)-a (show hidden items)-q (JMESPath filter)-v (verbose output)-o (save response to file)Fabric discovery follows a drill-down pattern:
fab ls
fab ls "ws.Workspace" -l
fab exists "ws.Workspace/Item"
fab desc .<ItemType>
fab get "ws.Workspace/Item"
fab get "ws.Workspace" -q "id"
fab find '<text>' -P type=<Type> -l
fab find (last visit, last refresh, owner, storage mode, capacity SKU, Copilot readiness): scripts/search_across_workspaces.py; see workspaces.md for the deltascripts/get-downstream-reports.py
Check references before exploring:
| Command | Purpose | Example |
|---|---|---|
fab get -q "definition" |
Get model schema | fab get "ws.Workspace/Model.SemanticModel" -q "definition" -f |
fab api -A powerbi |
Execute DAX | fab api -A powerbi "groups/<ws-id>/datasets/<model-id>/executeQueries" -X post -i '{"queries":[{"query":"EVALUATE..."}]}' |
fab ls |
Browse files / tables | fab ls "ws.Workspace/LH.Lakehouse/Files" |
fab table schema |
Lakehouse table schema | fab table schema "ws.Workspace/LH.Lakehouse/Tables/sales" |
fab cp |
Upload / download OneLake file | fab cp ./local.csv "ws.Workspace/LH.Lakehouse/Files/" |
duckdb + delta_scan |
Query Delta tables (requires DuckDB) | duckdb -c "... delta_scan('abfss://<ws-id>@onelake.../<lh-id>/Tables/schema/table')" |
duckdb + read_csv/json |
Query raw files (requires DuckDB) | duckdb -c "... read_csv('abfss://.../Files/data.csv')" |
Flags:
-A fabric|powerbi|storage|azure (API audience)-X get|post|put|delete|patch (HTTP method)-i (JSON body or file)-f (skip sensitivity prompt on definition pulls).Fabric exposes three query paths depending on the source; always prefer the wrapper scripts — they resolve IDs, hosts, and auth for you:
fab get "ws.Workspace/Model.SemanticModel" -q "definition"
scripts/execute_dax.py
scripts/query_lakehouse_duckdb.py (use tbl as a placeholder and pass -t schema.table)Files/: pass --sql with your own delta_scan() / read_csv / read_json_auto callsscripts/create_direct_lake_model.py
sqlcmd):
scripts/query_sql_endpoint.py (auto-detects host per item type, reuses az login via ActiveDirectoryAzCli)INFORMATION_SCHEMA, sys.* metadata, CTEs, or window functionsCheck references before writing queries:
| Command | Purpose | Example |
|---|---|---|
fab set |
Update property | fab set "ws.Workspace/Item" -q displayName -i "New Name" |
fab mv |
Rename / move item | fab mv "ws/Old.Notebook" "ws/New.Notebook" -f |
fab acl ls |
List permissions | fab acl ls "ws.Workspace" |
fab acl set |
Grant permission | fab acl set "ws.Workspace" -I <objectId> -R Member |
fab acl rm |
Revoke permission | fab acl rm "ws.Workspace" -I <upn> |
fab label set |
Set sensitivity label | fab label set "ws/Nb.Notebook" --name Confidential |
Flags:
-q <field> + -i <value> (set a single property)-I (object ID or UPN for fab acl)-R Admin|Member|Contributor|Viewer (role for fab acl set)-f (skip confirmation; ask user first if sensitivity labels are in play)Metadata and access changes fall into a few groups:
fab set "<path>" -q <field> -i "<value>"
fab get -v -o /tmp/before.json
fab commands):
fab api with item-specific endpointsfab acl set, fab acl rm
fab label set
az ad user show
.Report to a different .SemanticModel: reports.md
Check references before changing metadata:
| Command | Purpose | Example |
|---|---|---|
fab mkdir |
Create workspace / item | fab mkdir "New.Workspace" -P capacityname=MyCapacity |
fab assign |
Attach capacity / domain | fab assign .capacities/cap.Capacity -W ws.Workspace -f |
fab unassign |
Detach capacity / domain | fab unassign .capacities/cap.Capacity -W ws.Workspace |
fab start / fab stop |
Resume / pause capacity | fab start .capacities/cap.Capacity |
fab cp -r |
Fork workspace | fab cp "dev.Workspace" "prod.Workspace" -r -f |
fab rm |
Soft-delete (see recovery) | fab rm "ws/Item.Type" -f |
Flags:
-P key=value (creation params for fab mkdir)-W (target workspace for fab assign / fab unassign)-r (recursive copy/move)-bpc (block on path collision for fab cp)-f (skip confirmation)Workspace-scope operations fall into a few groups:
fab mkdir "<Name>.Workspace" -P capacityname=<cap>
fab assign .capacities/<cap>.Capacity -W <ws>.Workspace
fab cp -r "dev.Workspace" "prod.Workspace"
fab ls "dev.Workspace"
scripts/download_workspace.py
fab acl ls | set | rm
audit-tenant-settings skill from the fabric-admin pluginCheck references before modifying workspaces:
| Command | Purpose | Example |
|---|---|---|
fab job run |
Run synchronously | fab job run "ws/ETL.Notebook" -P date:string=2025-01-01 |
fab job start |
Run asynchronously | fab job start "ws/ETL.Notebook" |
fab job run-list |
List executions | fab job run-list "ws/Nb.Notebook" |
fab job run-status |
Check status | fab job run-status "ws/Nb.Notebook" --id <job-id> |
fab job run-cancel |
Cancel a job | fab job run-cancel "ws/Nb.Notebook" --id <job-id> -w |
fab api -A powerbi .../refreshes |
Trigger semantic model refresh | fab api -A powerbi "groups/<ws-id>/datasets/<model-id>/refreshes" -X post -i '{"type":"Full"}' |
Flags:
-P key:type=value (parameters, type is string|int|bool)--id (job run ID)-w (wait on cancel)--timeout (overall timeout for synchronous runs)--polling_interval (status poll cadence)Jobs map to different endpoints depending on item type:
fab job run "ws/ETL.Notebook" -P date:string=2025-01-01
fab job start "ws/ETL.Notebook"
fab job run-status "ws/Nb.Notebook" --id <job-id>
fab job run-list "ws/Nb.Notebook"
fab job):
fab api -A powerbi "groups/<ws-id>/datasets/<model-id>/refreshes" -X post -i '{"type":"Full"}'
fab api -A powerbi "groups/<ws-id>/datasets/<model-id>/refreshes?\$top=1"
Check references before running jobs:
| Command | Purpose | Example |
|---|---|---|
fab api "admin/items" |
Cross-workspace item search | fab api "admin/items" -P "type=SemanticModel" -q "itemEntities[?contains(name,'Sales')]" |
fab api "admin/workspaces" |
Workspace inventory | fab api "admin/workspaces" |
fab api "admin/tenantsettings" |
Tenant settings | fab api "admin/tenantsettings" |
fab api "admin/capacities" |
Capacity inventory | fab api "admin/capacities" |
fab api -X post .../update |
Update tenant setting | fab api -X post "admin/tenantsettings/<name>/update" -i body.json |
Flags:
-P key=value (query params, e.g. type=SemanticModel)-q (JMESPath filter)-X post + -i (write ops)--show_headers (inspect Retry-After on 429)Admin-scope work is gated behind the Fabric / Power BI admin role. Confirm access first with fab api "admin/capacities" 2>&1 | head -5; if it errors, stop rather than retry.
Two entry points cover most admin tasks:
audit-tenant-settings skill from the fabric-admin plugin. It owns the curated metadata baseline, the audit + change-detection script, delegated-override enumeration, and the Entra SG investigation workflow.Retry-After on 429Check references before admin work:
| Command | Purpose | Example |
|---|---|---|
fab get -q "definition" |
Read raw definition | fab get "ws/Model.SemanticModel" -q "definition" -f |
fab export |
Export item to local | fab export "ws/Nb.Notebook" -o ./backup -f |
fab import |
Import item from local | fab import "ws/Nb.Notebook" -i ./backup/Nb.Notebook -f |
fab cp |
Copy between workspaces | fab cp "dev/Item" "prod.Workspace" -f |
fab api "deploymentPipelines" |
Deployment pipelines API | fab api "deploymentPipelines" -q "value[]" |
Flags:
-o (output path for fab export)-i (input path or JSON body for fab import)--format (definition format for export / import)-f (skip overwrite and sensitivity prompts)Every Fabric item has a serializable definition. Move definitions between environments depending on scope:
fab export then fab import (always mkdir -p the output directory first; fab export does not create intermediate directories and fails with [InvalidPath])fab cp "dev/Item" "prod.Workspace"
scripts/export_semantic_model_as_pbip.py
scripts/download_workspace.py
allowPurgeData, allowTakeOver)Check references before deploying:
audit-tenant-settings (in the fabric-admin plugin) ; Fabric governance workflow covering tenant settings, delegated overrides (capacity / domain / workspace), and the Entra security groups those settings reference. Read-only; holds the curated metadata baseline and the audit + change-detection script.fab ls on items that aren't data items (.Lakehouse, .Warehouse, etc); use fab ls to find workspaces and items, and use fab get to look at definitions-f flag when using fab get, fab import, fab export, etc. as described abovefab api when a command doesn't existSkill references:
fab api (no native fab tag command)Scripts (scripts that you can execute):
fab find (last visit, last refresh, owner, storage mode, capacity SKU, Copilot readiness); see workspaces.md for when to choose whichaz login); output as table, csv, or jsonsqlcmd (reuses az login through ActiveDirectoryAzCli); output as table, csv, or jsonSee scripts/README.md for detailed usage, arguments, and examples. Always search the scripts/ folder before writing a new helper; a script may already exist for the task.
External references (request markdown when possible):
dax.guide/<function>/ e.g. dax.guide/addcolumns/
powerquery.guide/function/<function>