-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathPaginatedReport-Export.ps1
40 lines (26 loc) · 1.11 KB
/
PaginatedReport-Export.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
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1026" }
param(
$workspaceId = "cdee92d2-3ff9-43e2-9f71-0916e888ad27"
,
$reportId = "041eca9c-f5ad-465f-8153-dc257d56c485"
,
$format = "XLSX"
)
$ErrorActionPreference = "Stop"
$VerbosePreference = "SilentlyContinue"
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
Connect-PowerBIServiceAccount
$bodyStr = @{format=$format} | ConvertTo-Json
$result = Invoke-PowerBIRestMethod -url "groups/$workspaceId/reports/$reportId/ExportTo" -body $bodyStr -method Post
$status = $result | ConvertFrom-Json
while($status.status -in @("NotStarted", "Running"))
{
Write-Host "Sleeping..."
Start-Sleep -Seconds 5
$result = Invoke-PowerBIRestMethod -url "groups/$workspaceId/reports/$reportId/exports/$($status.id)" -method Get
$status = $result | ConvertFrom-Json
}
if ($status.status -eq "Succeeded")
{
$result = Invoke-PowerBIRestMethod -url "groups/$workspaceId/reports/$reportId/exports/$($status.id)/file" -method Get -OutFile "$currentPath\output\export.$format"
}