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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NandanHegde
Super User
Super User

How to extract the M Query meta data from Datamashup file via Powershell

Hey,

We are able to manually extract the Power query data from the Datamashup file through 7-zip tool.

Is there any way we can automate the extraction from Powershell?




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com
3 REPLIES 3
SpartaBI
Community Champion
Community Champion

Hi @NandanHegde,

You have a couple of options:
1. PBIX files include a backup of the AS database. In order to read the M queries you can restore the AS database either to a local AS server instance (by programmatically opening the PBIX file using Power BI Desktop then finding the localhost AS server port number) or to the Power BI Service (which can be done using APIs, or it may already be published...).

You can access an AS database using the AMO-TOM assemblies, which are built on .Net.
In order to connect to an AS database, you will use the XMLA endpoint. So for the Power BI service option, you will need to use premium (not needed for the local AS server instance option).

2. If the AS database is deployed to the Power BI Service, you can also get the M queries by using the Scanner APIs. This option is not limited to premium and does not require the AMO-TOM assemblies.

3. Another option is to convert a PBIX file to a PBIT file using Power BI Desktop. The latter contains the tabular model json representation. You can parse it to an object using ConvertFrom-Json (or using the AMO-TOM assemblies) and extract the M queries.

SpartaBI_1-1651151397708.png

 

SpartaBI_0-1651150169837.png

V-lianl-msft
Community Support
Community Support

Hi @NandanHegde ,

 

See if this will help:

https://github.com/cporteou/PowerBI-Metadata 


Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey,

Unfortunately the above Github code is for other PowerBI detals.

My requirement is to extract the source queries like say Select * from table in case if SQL is the source.

And it seems MSFT has removed the datamashup file from PBIX.

So is there any other way to get the source quuery details




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.