抱歉,这不仅仅是一行或两行代码,您可以轻松地将以下示例代码包装到可重用函数中:
$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)