Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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
Solved! Go to Solution.
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.
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
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.
Hello, the following post might be able to help you.
Good luck,
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!