-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathAdmin-GetGroupsAsAdmin.ps1
41 lines (28 loc) · 1.11 KB
/
Admin-GetGroupsAsAdmin.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
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1077" }
param (
$workspaces = @("cdee92d2-3ff9-43e2-9f71-0916e888ad27"),
$expand="users,reports,dashboards,datasets,dataflows,workbooks",
$outputPath = ".\output\getgroupsadmin"
)
$ErrorActionPreference = "Stop"
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
Set-Location $currentPath
New-Item -ItemType Directory -Path $outputPath -ErrorAction SilentlyContinue | Out-Null
try {
$token = Get-PowerBIAccessToken
}
catch {
$pbiAccount = Connect-PowerBIServiceAccount
}
foreach ($workspace in $workspaces)
{
$apiUrl = "admin/groups/$workspace"
if ($expand)
{
$apiUrl = $apiUrl + "?`$expand=$expand"
}
$workspacesScanRequests = Invoke-PowerBIRestMethod -Url $apiUrl -method Get | ConvertFrom-Json
$outputFilePath = "$outputPath\$workspace.json"
New-Item -Path (Split-Path $outputFilePath -Parent) -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
ConvertTo-Json $workspacesScanRequests -Depth 10 -Compress | Out-File $outputFilePath -force
}