-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtake over report.ps1
50 lines (34 loc) · 1.3 KB
/
take over report.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
# This sample script calls the Power BI API to progammatically take over a dataset.
# For documentation, please see:
# https://docs.microsoft.com/rest/api/power-bi/datasets/takeoveringroup
# Parameters - fill these in before running the script!
# =====================================================
# Login to the Power BI service with your Power BI credentials
Login-PowerBI
Get-PowerBIDataset
$workspaces = Get-PowerBIWorkspace
foreach ($workspace in $workspaces) {
$datasets = Get-PowerBIDataset -WorkspaceId $workspace.Id
"WORKSPACE: " + $workspace.Name
foreach ($dataset in $datasets) {
$datasetId = $dataset.Id
$workspaceId = $workspace.Id
"Taking over dataset: " + $dataset.Name
$uri = "groups/$workspaceId/datasets/$datasetId/Default.TakeOver"
$body = ""
# Try to bind to a new gateway
try {
Invoke-PowerBIRestMethod -Url $uri -Method Post -Body $body
# Show error if we had a non-terminating error which catch won't catch
if (-Not $?) {
$errmsg = Resolve-PowerBIError -Last
$errmsg.Message
}
}
catch {
5
$errmsg = Resolve-PowerBIError -Last
$errmsg.Message
}
}
}