2010-06-18 69 views
3

我在问这是因为我是一个n00b的涉及Powershell。使用Powershell在Reporting Services中设置用户权限

如何使用PowerShell来一个特定的域用户或组添加到SSRS2005特定报告的作用(说内容管理浏览器角色)?有一个简单的一行或两行脚本来实现它吗?

谢谢!

注意:这是绝对相关的编程(而不是服务器管理员),但我也要问这在SF上。

回答

10

对不起,它不只是一个或两行,但你可以很容易地包裹下面的示例代码为可重复使用的功能:

$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) 
+0

这是真棒,谢谢@Jason。我已经用VBScript和WMI做了,但是你发布的内容比我想象的要好得多。 – slugster 2011-02-15 06:17:08

+0

(1)我需要为$ Proxy变量的定义添加-UseDefaultCredential以使其起作用。 (2)我在$ ReportServerUri变量的定义末尾添加了“?wsdl”。感谢您的代码。 – 2016-11-17 14:14:57