如何通过PowerShell查找PowerBI报表所使用的链接/共享数据集
Hey Harry, I’ve run into this exact issue before—when a report connects to a shared dataset, the standard Get-PowerBIDatasource cmdlet won’t show you the linked dataset because it’s designed to pull direct data sources (like SQL Server or CSV), not references to shared datasets. Similarly, Get-PowerBIDataset alone won’t map the report to its linked dataset unless you know the right property to look for. Here are the reliable methods to fix this:
1. Use Get-PowerBIReport to Extract the Dataset ID
Every report connected to a shared dataset has a DatasetId property that directly links it to the underlying dataset. You can retrieve this with a simple PowerShell command:
# Replace "Your Report Name" with your actual report's name $report = Get-PowerBIReport -Name "Your Report Name" $linkedDatasetId = $report.DatasetId # Now fetch the full dataset details using the ID Get-PowerBIDataset -Id $linkedDatasetId | Select-Object Id, Name, IsRefreshable, CreatedDate
This will give you the exact shared dataset tied to your report, including its name and other key metadata.
2. Fall Back to the Power BI REST API
If the cmdlet approach doesn’t work (sometimes due to API version mismatches or permission edge cases), you can call the Power BI REST API directly from PowerShell:
# First, ensure you're connected to the Power BI service Connect-PowerBIServiceAccount # Get your report's ID $reportId = (Get-PowerBIReport -Name "Your Report Name").Id # Retrieve the access token for the API call $accessToken = Get-PowerBIAccessToken # Call the API to get the linked dataset $linkedDataset = Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/reports/$reportId/datasets" ` -Headers @{"Authorization" = "Bearer $accessToken"} # Output the dataset details (including direct service link) $linkedDataset.value | Select-Object id, name, webUrl
The webUrl property will even give you the direct link to the shared dataset in the Power BI service.
3. Verify Permissions and Dataset Type
Before troubleshooting further, double-check two critical points:
- Permissions: Make sure your account has at least Read access to both the report and the shared dataset. Without dataset-level permissions, the cmdlets/API will return empty results.
- Dataset Connection Type: Confirm your report is actually using a shared dataset (not imported data). In the Power BI service, go to your report > Settings > Datasets—you should see "Shared dataset" listed here.
内容的提问来源于stack exchange,提问作者Harry Leboeuf

