Using Powershell to Set User Permissions in Reporting Services

I ask about this because I am n00b when it comes to Powershell.

How to use Powershell to add a specific user or domain group to a specific reporting role in SSRS2005 (say, in the Content Manager or browser role)? Is there one or two lines of script to achieve it?

Thank!

Note: this is definitely related to programming (not the server administrator), but I will also ask about it on SF.

+3
source share
1 answer

Sorry, this is not only one or two lines, but you can easily wrap the following code example in a reusable function:

$ReportServerUri = 'http://myreportserver/ReportServer/ReportService2005.asmx'
$InheritParent = $true
$ItemPath = '/SomeReportFolder'
$GroupUserName = 'MYDOMAIN\SomeUser'
$RoleName = 'SomeReportServerRoleToGrant'

$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005

$Policies = $Proxy.GetPolicies($ItemPath, [ref]$InheritParent)

$Policy = $Policies | 
    Where-Object { $_.GroupUserName -eq $GroupUserName } | 
    Select-Object -First 1
if (-not $Policy) {
    $Policy = New-Object -TypeName SSRS.ReportingService2005.Policy
    $Policy.GroupUserName = $GroupUserName
    $Policy.Roles = @()
    $Policies += $Policy
}

$Role = $Policy.Roles |
    Where-Object { $_.Name -eq $RoleName } |
    Select-Object -First 1
if (-not $Role) {
    $Role = New-Object -TypeName SSRS.ReportingService2005.Role
    $Role.Name = $RoleName
    $Policy.Roles += $Role
}

$Proxy.SetPolicies($ItemPath, $Policies)
+10

Source: https://habr.com/ru/post/1750612/


All Articles