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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Get Datasources as Admin

I have 66K+ Datasets ids with me , I'm in need to find the datasets which belongs to particular Gateway. I currently use Get Datasources as a admin giving Dataset as parameter every single time. Can I create any query like for Loop so I can Feed Datasets and get relevant data on one shot ? please help me if anyone did before

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

Can you please try using PowerShell, which supports looping and API requests:

$clientId = "Your-Client-ID"
$tenantId = "Your-Tenant-ID"
$clientSecret = "Your-Client-Secret"
$datasets = @("DatasetID1", "DatasetID2", "DatasetID3")
$gatewayId = "Your-Gateway-ID"

$tokenUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$apiUrlBase = "https://api.powerbi.com/v1.0/myorg/admin/datasets"

$body = @{
    grant_type = "client_credentials"
    client_id = $clientId
    client_secret = $clientSecret
    scope = "https://analysis.windows.net/powerbi/api/.default"
}

$tokenResponse = Invoke-RestMethod -Method Post -Uri $tokenUrl -ContentType "application/x-www-form-urlencoded" -Body $body
$accessToken = $tokenResponse.access_token

$datasetDataSources = @()

foreach ($datasetId in $datasets) {
    $apiUrl = "$apiUrlBase/$datasetId/datasources"

    $response = Invoke-RestMethod -Method Get -Uri $apiUrl -Headers @{ Authorization = "Bearer $accessToken" }

    foreach ($dataSource in $response.value) {
        if ($dataSource.gatewayId -eq $gatewayId) {
            $datasetDataSources += [PSCustomObject]@{
                DatasetId = $datasetId
                DataSource = $dataSource
            }
        }
    }
}

$datasetDataSources | Format-Table -AutoSize

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

3 REPLIES 3
SaiTejaTalasila
Super User
Super User

Hi @Anonymous ,

 

I hope you have those dataset ID's on a CSV file.You can create a power shell with a function(get datasets rest API call) in a for loop and you can pass your dataset id recursively and get output and store those details to a CSV file.Even you can try with m-query using web connects.

 

I hope it will be helpful.

 

Thanks,

Sai Teja 

Sahir_Maharaj
Super User
Super User

Hello @Anonymous,

 

Can you please try using PowerShell, which supports looping and API requests:

$clientId = "Your-Client-ID"
$tenantId = "Your-Tenant-ID"
$clientSecret = "Your-Client-Secret"
$datasets = @("DatasetID1", "DatasetID2", "DatasetID3")
$gatewayId = "Your-Gateway-ID"

$tokenUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$apiUrlBase = "https://api.powerbi.com/v1.0/myorg/admin/datasets"

$body = @{
    grant_type = "client_credentials"
    client_id = $clientId
    client_secret = $clientSecret
    scope = "https://analysis.windows.net/powerbi/api/.default"
}

$tokenResponse = Invoke-RestMethod -Method Post -Uri $tokenUrl -ContentType "application/x-www-form-urlencoded" -Body $body
$accessToken = $tokenResponse.access_token

$datasetDataSources = @()

foreach ($datasetId in $datasets) {
    $apiUrl = "$apiUrlBase/$datasetId/datasources"

    $response = Invoke-RestMethod -Method Get -Uri $apiUrl -Headers @{ Authorization = "Bearer $accessToken" }

    foreach ($dataSource in $response.value) {
        if ($dataSource.gatewayId -eq $gatewayId) {
            $datasetDataSources += [PSCustomObject]@{
                DatasetId = $datasetId
                DataSource = $dataSource
            }
        }
    }
}

$datasetDataSources | Format-Table -AutoSize

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
blopez11
Super User
Super User

Hello, the following post might be able to help you.

https://community.fabric.microsoft.com/t5/Service/How-can-I-determine-which-datasets-are-using-a-gat...

 

Good luck,

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

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.