使用 Powershell 在 Reporting Services 中设置用户权限

发布于 2024-09-06 06:35:15 字数 211 浏览 7 评论 0原文

我问这个问题是因为我对 Powershell 很陌生。

如何使用 Powershell 将特定域用户或组添加到 SSRS2005 中的特定报告角色(例如内容管理员浏览器角色)?有没有一个简单的一两行脚本可以实现它?

谢谢!

注意:这肯定与编程相关(不是服务器管理),但我也会在 SF 上问这个问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陈独秀 2024-09-13 06:35:15

抱歉,它不仅仅是一两行,但您可以轻松地将以下示例代码包装到可重用函数中:

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

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)
人疚 2024-09-13 06:35:15

您可以使用以下脚本在 Reporting Services 中设置用户权限。
我使用它为用户设置 250 份报告的权限,我发现它很容易使用。

来源:
使用 Powershell 在 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文