-
Notifications
You must be signed in to change notification settings - Fork 0
/
Roles_Script.txt
88 lines (43 loc) · 2.25 KB
/
Roles_Script.txt
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
76
77
78
79
80
81
82
83
84
85
86
87
88
#****************
#------------------------------------------------------
# --> PBI Connection
#------------------------------------------------------
Write-Host " PBI credentials ..." -ForegroundColor Yellow -BackgroundColor DarkGreen
## PBI credentials
$password = "venkatspassword" | ConvertTo-SecureString -asPlainText -Force
$username = "[email protected]"
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
## PBI connect
Connect-PowerBIServiceAccount -Credential $credential
#****************
#------------------------------------------------------
# --> 1. API Call for WORKSPACE USERS
#------------------------------------------------------
Write-Host " API Call ..." -ForegroundColor Yellow -BackgroundColor DarkGreen
$GroupWorkspaceId = "c82a4936-11be-43a9-b879-2f09e1708a6f" #get workspace ID from web url
$WorkspaceObject = Get-PowerBIWorkspace -Scope Individual -Id $GroupWorkspaceId
Write-Host $WorkspaceObject
$pbiURL = "https://api.powerbi.com/v1.0/myorg/groups/$GroupWorkspaceId/users"
##Write-Host $pbiURL
## API call
$resultJson = Invoke-PowerBIRestMethod –Url $pbiURL –Method GET
$resultObject = ConvertFrom-Json -InputObject $resultJson
##Write-Host $resultObject
## Collect data fields for each loop
$WorkspaceUsers += $resultObject.Value |
SELECT @{n='WorkspaceId';e={$GroupWorkspaceId}},
@{n='Workspace';e={$WorkspaceObject.Name}},
displayName,
emailAddress,
@{n='UserRole';e={$_.groupUserAccessRight}},
@{n='Principle';e={$_.principalType}} |
SELECT Workspace, displayName, UserRole, Principle, emailAddress |
SORT Principle, UserRole, displayName
##Write-Host $WorkspaceUsers
## Print loop results
$WorkspaceUsers | ft -auto ##| Where{$_.WorkspaceId -eq $GroupWorkspaceId}
clear-variable -name resultJson
clear-variable -name resultObject
## Export user access for all workspaces
$WorkspaceUsers | SORT Workspace, UserRole, displayName | Out-GridView
clear-variable -name WorkspaceUsers