Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi!
I am trying to write a Powershell script that would refresh all reports that have refresh schedules enabled.
The refresh api call should have a condition to only use dataset ids with refresh enabled. Currently refreshes all datasets.
The API call foreach code block should work like this: Loop datasetIds which have refresh schedule enable = true.
I might need to store the dataset ids with schedule enabled to a list or an array and loop those in the foreach bit to do this, but I am not sure how.
Here is my script. The part that requires input is the last one. Commented # POST Refresh datasets
# Parameters
$clientId = "xxxx-xxxx-xxx"
$tenantId = "xxxx-xxxx-xxx"
$clientSecret = "xxxx-xxxx-xxx"
$groupID = "xxxx-xxxx-xxx"
# End Parameters
# POST AuthToken
$body = @{
"grant_type" = "client_credentials"
"client_id" = $clientId
"client_secret" = $clientSecret
"scope" = "https://analysis.windows.net/powerbi/api/.default"
}
$authUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$authResponse = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
$headers = @{
"Content-Type" = "application/json";
"Authorization" = $authResponse.token_type + " " +
$authResponse.access_token
}
# GET group id for URI
$groupsPath = ""
if ($groupID -eq "me") {
$groupsPath = "myorg"
} else {
$groupsPath = "myorg/groups/$groupID"
}
$uril = "https://api.powerbi.com/v1.0/$groupsPath"
$restResponse1 = Invoke-RestMethod -Uri $uril -Method GET -Headers $headers
# GET dataset ids
$x = $restResponse1.id
$groupID = $x.Id #workspace Id
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets"
$GETdatasetID = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
$d = $GETdatasetID.value
# GET Refresh schedules
foreach($j in $d) {
$datasetID=$j.Id #dataset Id
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets/$datasetID/refreshSchedule"
$GETrefreshSchedule = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
}
# POST Refresh datasets
# This should have a condition to only use dataset ids with refresh enabled: $GETrefreshSchedule.enabled = "True"
# Currently refreshes all datasets
foreach($j in $d) {
$datasetID=$j.Id #dataset Id
$uri = "https://api.powerbi.com/v1.0/$groupsPath/$groupID/datasets/$datasetID/refreshes"
$POSTrefreshDataset = Invoke-RestMethod -Uri $uri -Method POST -Headers $headers
}
Hi @Smamwise ,
You can refer to the following documentation and see if it helps you to "create a list or an array and loop those in the foreach bit".
azure - How do I properly use ForEach() statement of List? - Stack Overflow
PowerShell array initialization - Stack Overflow
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
7 | |
7 | |
3 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
4 |