Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
aWalsh523
New Member

Using PowerShell to get PowerBI SQL connection strings

Looking for an automated way to identify all SQL sources for a PowerBI dataset. Would like a way in PowerShell to get a list of connections for a PowerBI Dataset, then for each connection get the SQL statement (query text found under the 'Advanced Options' in PBI desktop).  Shown here in red:

 

Untitled.png

 

 

 

 

 

 

I've tried MicrosoftPowerBIMgmt Get-PowerBIDatasource function as well as the Power BI REST API for Get Datasources. These both include the 'server' and 'database' fields that are found on the connection setup screen, but do not include the actual query text.  

 

Alternately, if a connection does not include SQL query text, would there be a way to access the 'Navigate' step in the 'Applied Steps'?

 

From the SQL query text or text from the 'Navigate' step I can then parse the text as needed.

 

Any help or suggestions would be appreciated!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @aWalsh523,

AFAIk, current you can't directly get the advanced SQL statement from the data connector by rest API.
It should be more suitable to trace these on the database side or you can consider parameterized t-sql string with query parameters, then you can use the rest API to get query parameters to get detailed t-sql queries.

Using the Power BI Service Parameters to change connection strings (To possibly change between Dev 

let
    source=Sql.Database("server", "database",[Query=SQLParameter])
in 
    source

Datasets - Get Parameters - REST API (Power BI Power BI REST APIs) | Microsoft Docs

Regards,

Xiaoxin Sheng

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @aWalsh523,

AFAIk, current you can't directly get the advanced SQL statement from the data connector by rest API.
It should be more suitable to trace these on the database side or you can consider parameterized t-sql string with query parameters, then you can use the rest API to get query parameters to get detailed t-sql queries.

Using the Power BI Service Parameters to change connection strings (To possibly change between Dev 

let
    source=Sql.Database("server", "database",[Query=SQLParameter])
in 
    source

Datasets - Get Parameters - REST API (Power BI Power BI REST APIs) | Microsoft Docs

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors