开发者

Using Powershell to set user permissions in Reporting Services

开发者 https://www.devze.com 2023-01-04 02:03 出处:网络
I\'m asking this because i\'m a n00b when it comes to Powershell. How do i use Powershell to add a particular dom开发者_开发问答ain user or group to a specific reporting role in SSRS2005 (say the Co

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

How do i use Powershell to add a particular dom开发者_开发问答ain 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.


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)


you can use below script to set user permissions in Reporting services. I use this for set permission to a user on 250 reports and I found it easy to use.

source: Using Powershell to set user permissions in Reporting Services

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号