道歉,如果这似乎是一个gimme-teh codez问题,但我问这是因为我是一个n00b当涉及到Powershell。
如何使用Powershell将特定的域用户或组添加到SSRS2008中的特定报告angular色(如内容pipe理器或浏览器angular色)? 有一个简单的一行或两行脚本来实现它吗?
谢谢!
(我以前在这里发布过这个问题)。
我遇到这个问题,同时试图find一样的我自己。
最后,我写了这个函数,它可以和SSRS 2008一起工作(按原来的要求),一直到SSRS(2016)的最新版本。
惠斯特不是一个双线的答案,它确实定义了一个函数,一旦创build,就提供了一个单线方法……所以在我看来,这很重要(特别是因为你不能只用两行来做)。
希望有人认为它有用!
function Add-SSRSUserRole ( [string]$reportServerUrl,[string]$userGroup,[string]$requiredRole,[string]$folder,[bool]$inheritFromParent ) { #Ensure we stop on errors $ErrorActionPreference = "Stop"; #Connect to the SSRS webservice $ssrs = New-WebServiceProxy -Uri "$reportServerUrl" -UseDefaultCredential; $namespace = $ssrs.GetType().Namespace; $changesMade = $false; #Look for a matching policy $policies = $ssrs.GetPolicies($folder, [ref]$inheritFromParent); if ($policies.GroupUserName -contains $userGroup) { Write-Host "User/Group already exists. Using existing policy."; $policy = $policies | where {$_.GroupUserName -eq $userGroup} | Select -First 1 ; } else { #A policy for the User/Group needs to be created Write-Host "User/Group was not found. Creating new policy."; $policy = New-Object -TypeName ($namespace + '.Policy'); $policy.GroupUserName = $userGroup; $policy.Roles = @(); $policies += $policy; $changesMade = $true; } #Now we have the policy, look for a matching role $roles = $policy.Roles; if (($roles.Name -contains $requiredRole) -eq $false) { #A role for the policy needs to added Write-Host "Policy doesn't contain specified role. Adding."; $role = New-Object -TypeName ($namespace + '.Role'); $role.Name = $requiredRole; $policy.Roles += $role; $changesMade = $true; } else { Write-Host "Policy already contains specified role. No changes required."; } #If changes were made... if ($changesMade) { #...save them to SSRS Write-Host "Saving changes to SSRS."; $ssrs.SetPolicies($folder, $policies); } Write-Host "Complete."; } [string]$url = "http://localhost/ReportServer/ReportService2006.asmx?wsdl"; Add-SSRSUserRole $url "Everyone" "Browser" "/MyReportFolder" $true; Add-SSRSUserRole $url "Domain\User" "Browser" "/MyReportFolder" $true;