-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSSRS-SetSysPermissions.ps1
147 lines (110 loc) · 4.28 KB
/
SSRS-SetSysPermissions.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Created by EGGSTOASTBACON :: https://github.com/eggstoastbacon
#Function for adding Users to Power-Bi Report Server, SSRS, Reporting Services
#Must be run from somewhere that has access to your report services website
#Usage: SSRS-setSysPermissions -User "$user" -roles "User"
#Roles: admin, user, schedule, msbi
#Important! Modify the groups in this script to your match your environment first
function SSRS-setSysPermissions {
param ([string]$user, [string]$roles)
Clear-variable policy –erroraction silentlycontinue
Clear-variable policies –erroraction silentlycontinue
$domain = "DOMAIN"
$password = Get-Content D:\YOUR\ENC\PASSWORD.ENC | ConvertTo-SecureString
$LogonUser = "username"
$URL = "http://localhost:80/ReportServer"
$ReportServerUri = "$URL/ReportService2010.asmx"
$Proxy = New-WebServiceProxy -Uri $ReportServerUri
$Proxy.CookieContainer = New-Object System.Net.CookieContainer(10);
$Proxy.LogonUser("$logonUser", "$password", "$domain")
if ($folder) {
$folder = "/" + $folder
}
else { write-host "Specify Folder" }
$input_user = $user
$input_role = $roles
$InheritParent = $true
$System_Administrator = "False"
$System_User = "False"
$My_Reports = "False"
$Schedules = "False"
$MSBI_Developers_System_Role = "False"
if ($input_role) {
if ($input_role -like "*Admin*") {
$System_Administrator = "True"
}
if ($input_role -like "*User*") {
$System_User = "True"
}
if ($input_role -like "*Schedule*") {
$Schedules = "True"
}
if ($input_role -like "*MSBI*") {
$MSBI_Developers_System_Role = "True"
}
}
else { write-host "Specify permissions" }
$type = $Proxy.GetType().Namespace;
$policies = @()
$policyType = "{0}.Policy" -f $type;
$roleType = "{0}.Role" -f $type;
if ($user) {
$Policy = New-Object ($policyType)
$Policy.GroupUserName = $user
$a = New-Object ($roleType)
$b = New-Object ($roleType)
$c = New-Object ($roleType)
$d = New-Object ($roleType)
if ($System_Administrator -eq "True") {
$a.Name = 'System Administrator'
$Policy.Roles += $a
}
if ($System_User -like "True") {
$b.Name = 'System User'
$Policy.Roles += $b
}
if ($Schedules -like "True") {
$c.Name = 'Schedules'
$Policy.Roles += $c
}
if ($Schedules -like "True") {
$d.Name = 'MSBI_Developers_System_Role'
$Policy.Roles += $d
}
$policies += $policy
}
else { write-host "Specify username" }
$permissions = $proxy.getSystempolicies()
foreach ($permission in $permissions) {
$Policy = New-Object ($policyType)
clear-variable a -ErrorAction SilentlyContinue
clear-variable b -ErrorAction SilentlyContinue
clear-variable c -ErrorAction SilentlyContinue
clear-variable d -ErrorAction SilentlyContinue
clear-variable e -ErrorAction SilentlyContinue
if ($permission.GroupUserName -notlike "*$User*") {
$Policy.GroupUserName = $permission.GroupUserName
$a = New-Object ($roleType)
$b = New-Object ($roleType)
$c = New-Object ($roleType)
$d = New-Object ($roleType)
if ($permission.roles.name -like "*Admin*") {
$a.Name = 'System Administrator'
$Policy.Roles += $a
}
if ($permission.roles.name -like "*User*") {
$b.Name = 'System User'
$Policy.Roles += $b
}
if ($permission.roles.name -like "*Schedule*") {
$c.Name = 'Schedules'
$Policy.Roles += $c
}
if ($permission.roles.name -like "*MSBI*") {
$d.Name = 'MSBI_Developers_System_Role'
$Policy.Roles += $d
}
$policies += $policy
}
}
$Proxy.SetSystemPolicies($policies);
}