Using Powershell to set user permissions in Reporting Services

天大地大妈咪最大 提交于 2019-12-05 03:03:59

问题


I'm asking this because i'm a n00b when it comes to Powershell.

How do i use Powershell to add a particular domain user or group to a specific reporting role in SSRS2005 (say the Content Manager or Browser role)? Is there a simple one or two line script to achieve it?

Thanks!

Note: this is definately programming related (not server admin), but i am also going to ask this on SF.


回答1:


Sorry, it isn't just one or two lines but you could easily wrap the following sample code into 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)


来源:https://stackoverflow.com/questions/3066869/using-powershell-to-set-user-permissions-in-reporting-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!