Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
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.
User | Count |
---|---|
10 | |
5 | |
4 | |
4 | |
3 |
User | Count |
---|---|
14 | |
9 | |
5 | |
5 | |
4 |