-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSRS-RemSysPermissions.ps1
86 lines (62 loc) · 2.5 KB
/
SSRS-RemSysPermissions.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
#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-RemSysPermissions -User "$user"
#Important! Modify the groups in this script to your match your environment first
function SSRS-RemSysPermissions {
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")
$type = $Proxy.GetType().Namespace;
$policies = @()
$policyType = "{0}.Policy" -f $type;
$roleType = "{0}.Role" -f $type;
if ($user) {}
else { write-host "Specify username" }
$permissions = $proxy.getSystempolicies()
if($user -in $permissions.GroupUserName) {
foreach($permission in $permissions) {
if ($permission.GroupUserName -notlike "*$User*") {
$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);
}
}