-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDataset-RefreshAsync.ps1
75 lines (54 loc) · 2.23 KB
/
Dataset-RefreshAsync.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1026" }
param(
$workspaceId = "6b75551a-6107-4688-a1bf-f6a8eb52df71"
,
$datasetId = "d6ba1cf6-ca85-4676-9db5-fa91c3c69f19"
,
$type = "full"
,
$maxParallelism = 6
,
$commitMode = "transactional"
#$commitMode = "partialBatch"
,
$retryCount = 1
,
$objects = @(
)
)
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
$executeJsonObj = @{
"type" = $type
;
"commitMode" = $commitMode
;
"maxParallelism" = $maxParallelism
;
"retryCount" = $retryCount
;
"objects" = $objects
}
$executeJsonBody = $executeJsonObj | ConvertTo-Json -Depth 5
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"
$refreshes = Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes?`$top=10" -method Get | ConvertFrom-Json | select -ExpandProperty value
if (!($refreshes |? { $_.refreshType -eq "ViaEnhancedApi" -and $_.status -iin @("Unknown", "inProgress", "notStarted") }))
{
Write-Host "Posting a new Refresh Command"
Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes" -method Post -Body $executeJsonBody
}
Write-Host "Waiting for refresh to end"
$refreshes = Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes?`$top=10" -method Get | ConvertFrom-Json | select -ExpandProperty value
$refreshId = $refreshes[0].requestId
do
{
$refreshDetails = Invoke-PowerBIRestMethod -url "groups/$workspaceId/datasets/$datasetId/refreshes/$refreshId" -method Get | ConvertFrom-Json
Write-Host "Status: $($refreshDetails.status)"
Write-Host ($refreshDetails.objects | format-table | out-string)
Write-Host "sleeping..."
Start-Sleep -Seconds 2
}
while($refreshDetails.status -iin @("Unknown", "inProgress", "notStarted"))
Write-Host "Refresh complete: $((([datetime]$refreshDetails.endTime) - ([datetime]$refreshDetails.startTime)).TotalSeconds)s"
$refreshDetails | Format-Table
$refreshDetails.objects | Format-Table