-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSRS-RemPermissions.ps1
99 lines (75 loc) · 3.4 KB
/
SSRS-RemPermissions.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
#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-remPermissions -User "$user" -folder "$path"
#Important! Modify the groups in this script to your match your environment first
function SSRS-remPermissions {
param ([string]$user, [string]$folder)
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("$ogonUser", "$password", "$domain")
if ($folder) {
$folder = $folder
}
else { write-host "Specify Folder" }
$input_user = $user
$InheritParent = $true
$type = $proxy.GetType().Namespace;
$policies = @()
$policyType = "{0}.Policy" -f $type;
$roleType = "{0}.Role" -f $type;
$permissions = $proxy.getpolicies($folder, [ref]$InheritParent)
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
clear-variable f -ErrorAction SilentlyContinue
$Policy.GroupUserName = $permission.GroupUserName
$a = New-Object ($roleType)
$b = New-Object ($roleType)
$c = New-Object ($roleType)
$d = New-Object ($roleType)
$e = New-Object ($roleType)
$f = New-Object ($roleType)
if ($permission.roles.name -like "*Content*") {
$a.Name = 'Content Manager'
$Policy.Roles += $a
}
if ($permission.roles.name -like "*Browser*") {
$b.Name = 'Browser'
$Policy.Roles += $b
}
if ($permission.roles.name -like "*My*") {
$c.Name = 'My Reports'
$Policy.Roles += $c
}
if ($permission.roles.name -like "*Pub*") {
$d.Name = 'Publisher'
$Policy.Roles += $d
}
if ($permission.roles.name -like "*Report*") {
$e.Name = 'Report Builder'
$Policy.Roles += $e
}
if ($permission.roles.name -like "*MSBI*") {
$f.Name = 'MSBI_Developers_Role'
$Policy.Roles += $f
}
$policies += $policy
}
}
$Proxy.SetPolicies("$folder", $policies);
}
}