-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDataset-RefreshAsync-Cancel.ps1
44 lines (27 loc) · 1.46 KB
/
Dataset-RefreshAsync-Cancel.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1026" }
param(
$workspaceId = "cdee92d2-3ff9-43e2-9f71-0916e888ad27"
,
$datasetId = "ff63139f-eea9-4296-a5e4-3f56c0005701"
)
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
Connect-PowerBIServiceAccount
# Get running refreshes, only 1 operation is allowed "Only one refresh operation at a time is accepted for a dataset. If there's a current running refresh operation and another is submitted"
Write-Host "Get Runnning Refreshes"
$refreshes = Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes?`$top=5" -method Get | ConvertFrom-Json | select -ExpandProperty value
$refreshes = @($refreshes |? { $_.extendedStatus -in @("Unknown", "inProgress", "notStarted") })
Write-Host "Canceling '$($refreshes.Count)' refreshes"
foreach($refresh in $refreshes)
{
$refreshId = $refresh.requestId
do
{
Write-Host "Cancelling..."
Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes/$refreshId" -method Delete | ConvertFrom-Json
$refreshDetails = Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes/$refreshId" -method Get | ConvertFrom-Json
Write-Host "Status: $($refreshDetails.status)"
Write-Host "sleeping..."
Start-Sleep -Seconds 2
}
while($refreshDetails.extendedStatus -iin @("notStarted", "Unknown", "inProgress"))
}