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!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hi everyone,
we have a number of "production" datasets, and these seem to fail to refresh occasionally. Uncertain why - maybe network hiccup, PBI service issue, database being backed up on our side, etc.
Long and short, I'm trying to write a script that will loop through every dataset in our production workspaces, check whether a) the dataset is set up to refresh, and b) if so did the last refresh work properly. Unfortunately I'm not a PowerShell developer (at all...) so I'm hitting some issues.
The main piece of code I have is:
$AllDatasets =
ForEach ($workspace in $Workspaces)
{
ForEach ($dataset in (Get-PowerBIDataset -Scope Organization -WorkspaceId $workspace.Id))
{
# check if dataset is supposed to refresh
$url = "https://api.powerbi.com/v1.0/myorg/groups/" + $workspace.Id + "/datasets/" + $dataset.ID + "/refreshSchedule"
$refreshSched = $false
$refreshSched = (ConvertFrom-Json (Invoke-PowerBIRestMethod -Url $url -Method Get)).enabled
# check status of last refresh
$url = "https://api.powerbi.com/v1.0/myorg/groups/" + $workspace.Id + "/datasets/" + $dataset.ID + '/refreshes?$top=1'
#Write-Host $url
$last_status = "n/a"
$last_status = (ConvertFrom-Json (Invoke-PowerBIRestMethod -Url $url -Method Get)).value.status
[pscustomobject]@{
WorkspaceName = $workspace.Name
WorkspaceID = $workspace.Id
DatasetName = $dataset.Name
DatasetID = $dataset.Id
DatasetAuthor = $dataset.ConfiguredBy
Refresh = $refreshSched
LastStatus = $last_status
}
}
}This seems to work pretty well - but it throws errors. For example, the bit of code where it calls the "/refreshSchedule" fails if the dataset isn't set to be refreshed. Ditto for when it calls the last status $top=1 bit.
Is there a simple way for me to test whether a dataset is set up to be refreshed, other than calling the /refreshSchedule API and getting an error back? And/or is there a better way to handle the error? I thought I could use the "IsRefreshable" field when querying the dataset itself...but that seems to be set to TRUE even for datasets that aren't scheduled to refresh.
Thanks!
Scott
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |