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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Fetching data sources from dataset using PowerShell script

Hi All,

 

Can anyone please provide the Powershell script to fetch the data sources from each and every dataset in Power BI service.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
aj1973
Community Champion
Community Champion

It is saying that the command

aj1973_0-1698150831928.png

you either re install the module

aj1973_1-1698150952389.png

Or it could be also

aj1973_2-1698151012733.png

Therefore you need a Service account or Power BI App Registration

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

View solution in original post

11 REPLIES 11
aj1973
Community Champion
Community Champion

Hi @Anonymous 


Get-PowerBIDataset -Scope Organization |
Foreach {
$dsID = $_.Id;
$dsName = $_.Name;
Get-PowerBIDatasource -DatasetId $dsID -Scope Organization |
Foreach {
[PSCustoMObject]@{

'WSID' = $wsId;
'WSName' = $wsName;
'DSID' = $dsID;
'DSName' = $dsName;
'SrcId' = $_.DatasourceId;
'SrcName' = $_.Name;
'DatasourceType' = $_.DatasourceType;
'ConnectionString' = $_.ConnectionString;
'ConnectionDetails.server' = $_.ConnectionDetails.server;
'ConnectionDetails.database' = $_.ConnectionDetails.database;
'ConnectionDetails.Url' = $_.ConnectionDetails.Url;
'GatewayId' = $_.GatewayId

}
}
}| ConvertTo-Json | Out-File -FilePath "D:\Logs\Inventaire\Datasources\PowerBI_Datasources_$(Get-Date -Format yyyyMMdd).json" -Encoding utf8 -Force

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Hi @aj1973 ,

 

Thanks for responding to me, As you suggested i ran the powershell but getting the below error. May i know why i am getting the below error.

 

Ynr0225_0-1698091456958.png

Thanks in advance!

aj1973
Community Champion
Community Champion

Can't see the error

Are you Power BI Admin?

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Below is the error message and yes i am the Power BI admin.

 

Get-PowerBIDatasource : Operation returned an invalid status code 'NotFound'
At line:6 char:1
+ Get-PowerBIDatasource -DatasetId $dsID -Scope Organization |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...werBIDatasource:GetPowerBIDatasource) [Get-PowerBIDatasource], HttpOper
ationException
+ FullyQualifiedErrorId : Operation returned an invalid status code 'NotFound',Microsoft.PowerBI.Commands.Data.GetPowerBIDatasou
rce

Thanks,

Nagendra Y

aj1973
Community Champion
Community Champion

It is saying that the command

aj1973_0-1698150831928.png

you either re install the module

aj1973_1-1698150952389.png

Or it could be also

aj1973_2-1698151012733.png

Therefore you need a Service account or Power BI App Registration

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Hello @aj1973 

As you suggested i reinstall the module again but same results

Ynr0225_0-1699611886790.pngYnr0225_1-1699611916153.png

 

aj1973
Community Champion
Community Champion

You have an authantication problem. How do you connect to the service? are you using an App registration? eventhough you are Power Admin, are you allowed to use and read the REST APIs power bi? check the Admin portal to be allowed

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

I am using both App registration and my credentials but getting same results. App registration have Power BI admin access and added as an admin of all workspaces in premium capacity. Yes i allowed to use and read the REST APIs power bi below ias screenshot.

Ynr0225_0-1699639874958.png

 

aj1973
Community Champion
Community Champion

When using the App Registration, is the private key installed in the machine/server that executes the script?

Can you please show me how do you connect and execute the script *.ps1?

 

The way you are connecting now, can you run just this API "Get-PowerBIDataset -Scope Organization" and tell me if it returns a result?

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Anonymous
Not applicable

Using clientid and clientsecret we are connecting the power bi service and running script which is as follows:

$AppId = "Application ID"
$TenantId = "Tenant ID"
$ClientSecret = "Clientsecret"

#Create secure string & credential for application id and client secret
$PbiSecurePassword = ConvertTo-SecureString $ClientSecret -Force -AsPlainText
$PbiCredential = New-Object Management.Automation.PSCredential($AppId, $PbiSecurePassword)

#Connect to the Power BI service
Connect-PowerBIServiceAccount -ServicePrincipal -TenantId $TenantId -Credential $PbiCredential

 

Get-PowerBIDataset -Scope Organization |
Foreach {
$dsID = $_.Id;
$dsName = $_.Name;
Get-PowerBIDatasource -DatasetId $dsID -Scope Organization |
Foreach {
[PSCustoMObject]@{

'WSID' = $wsId;
'WSName' = $wsName;
'DSID' = $dsID;
'DSName' = $dsName;
'SrcId' = $_.DatasourceId;
'SrcName' = $_.Name;
'DatasourceType' = $_.DatasourceType;
'ConnectionString' = $_.ConnectionString;
'ConnectionDetails.server' = $_.ConnectionDetails.server;
'ConnectionDetails.database' = $_.ConnectionDetails.database;
'ConnectionDetails.Url' = $_.ConnectionDetails.Url;
'GatewayId' = $_.GatewayId

}
}
}| ConvertTo-Json | Out-File -FilePath "D:\Logs\Inventaire\Datasources\PowerBI_Datasources_$(Get-Date -Format yyyyMMdd).json" -Encoding utf8 -Force

 

As you suggested i have run just API "Get-PowerBIDataset -Scope Organization" and getting results with out any issues.

aj1973
Community Champion
Community Champion

@Anonymous 

This is not the right way to access with App registration

aj1973_0-1700159697183.png

It is like you are converting the App registration into a User with credentials and PSW, False.

 

This is the right way:

Connect-PowerBIServiceAccount -ServicePrincipal -CertificateThumbprint 38DA4BED389A014E69A6E6D8AE56761E85F0DFA4 -ApplicationId b5fde143-722c-4e8d-8113-5b33a9291468

aj1973_2-1700160790100.png

You need :

aj1973_3-1700160865854.png

 

If this is not a good option for you to install CertificateThumbprint,(Recommended) then there is another way but little longer since you can call APIs(Your way) one by one.

 

Let me know. 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.