【问题标题】:How to remove a user from SSRS folder security using Powershell如何使用 Powershell 从 SSRS 文件夹安全性中删除用户
【发布时间】:2016-06-01 17:01:34
【问题描述】:

我正在使用 ReportService2010 和 Powershell 4.0 以编程方式创建 SSRS 文件夹安全性。我可以创建文件夹,然后成功地将用户添加到文件夹安全性。

我的要求是
我想将所有用户添加到主文件夹(浏览器角色)。但是对于主文件夹下的文件夹,只有选定的用户才能访问选定的文件夹。

但是由于从主文件夹继承,所有用户都获得了所有文件夹的浏览器角色。所以我需要使用 Powershell 从文件夹安全中删除不需要的用户。我一直在寻找很长时间,但找不到一个有用的帖子。

如何以编程方式从文件夹的安全性中删除用户或组?

编辑

用于添加文件夹和文件夹安全性的代码
我为 SSRS 代理使用全局变量

function Add-SSRSFolder(
    [Parameter(Position=0,Mandatory=$true)]
    [string]$folderName,

    [Parameter(Position=1,Mandatory=$true)]
    [string]$Parent
)
{
    #get autogenerated namespace
    $type = $ssrsProxy.GetType().Namespace
    $datatype = ($type + '.Property')

    #Here we create a new object of Property type and set properties
    $property = New-Object ($datatype);
    $property.Name = “Description”
    $property.Value = “”

    #Report SSRS Properties
    #we need a property array to pass to the CreateFolder method
    $numproperties = 1
    $properties = New-Object ($datatype + '[]')$numproperties 
    $properties[0] = $property;

    write-host "Creating New Folder...... $foldername" 
    $newFolder = $ssrsProxy.CreateFolder($foldername, $Parent, $properties);
}


function Add-SSRSItemSecurity
(
    [Parameter(Position=0,Mandatory=$true)]
    [string]$itemPath,

    [Parameter(Position=1,Mandatory=$true)]
    [string]$groupUserName,

    [Parameter(Position=2,Mandatory=$true)]
    [string]$role,

    [Parameter(Position=3)]
    [bool]$inherit=$true
)
{
    $type = $ssrsProxy.GetType().Namespace;
    $policyType = "{0}.Policy" -f $type;
    $roleType = "{0}.Role" -f $type;

    $policies = $ssrsProxy.GetPolicies($itemPath, [ref]$inherit);

    $Policy = $policies | 
    Where-Object { $_.GroupUserName -eq $groupUserName } | 
    Select-Object -First 1

    if (-not $Policy) {
        $Policy = New-Object ($policyType)
        $Policy.GroupUserName = $GroupUserName
        $Policy.Roles = @()
        $Policies += $Policy
        $msg = "[Add-SSRSItemSecurity()] Adding new policy: '{0}'" -f $GroupUserName
        Write-Host $msg
    }

    $r = $Policy.Roles |
        Where-Object { $_.Name -eq $role } |
        Select-Object -First 1
    if (-not $r) {
        $r = New-Object ($roleType)
        $r.Name = $role
        $Policy.Roles += $r
        $msg = "[Add-SSRSItemSecurity()] Adding new role: '{0}'" -f $role
        Write-Host $msg
    }

    $ssrsProxy.SetPolicies($itemPath,$policies);
}

请有人帮忙。 谢谢

【问题讨论】:

  • 到目前为止你写了什么代码,有没有给你任何错误?这种过程已经在本网站上反复讨论过,所以应该有一个适合您需求的答案,除非情况非常特殊。
  • 没有错误,因为我还没有尝试过。我找不到删除文件夹安全性的方法。我已经用我用来创建文件夹和添加安全性的代码更新了这个问题。

标签: powershell reporting-services ssrs-2012 reportingservices-2005 reportservice2010


【解决方案1】:

这是从所有文件夹或特定文件夹中删除用户的代码。

我还在 SQLShack 上写过这个和类似的脚本

#---------------------------------------------
# Author:   Craig Porteous
#           @cporteous
# Synopsis: Remove a specific user/group from 
#           all SSRS (native mode) folders. 
#           Excludes inherited folders
#---------------------------------------------

Clear-Host
$ReportServerUri = 'http://PorteousSQL1/ReportServer/ReportService2010.asmx?wsdl'
$InheritParent = $true
$GroupUserName = 'PORTEOUSSQL1\pInstall'
$folder = '/'

$rsProxy = New-WebServiceProxy -Uri $ReportServerUri -UseDefaultCredential
#List out all subfolders under the parent directory
$items = $rsProxy.ListChildren($folder, $true) | `
         SELECT TypeName, Path, ID, Name | `
         Where-Object {$_.typeName -eq "Folder"}
#Iterate through every folder        
foreach($item in $items)
{
    $Policies = $rsProxy.GetPolicies($Item.Path, [ref]$InheritParent)
    #Skip over folders marked to Inherit permissions. No changes needed.
    if($InheritParent -eq $false)
    {
        #List out ALL policies on folder but do not include the policy for the specified user/group
        $Policies = $Policies | Where-Object { $_.GroupUserName -ne $GroupUserName }
        #Set the folder's policies to this new set of policies
        $rsProxy.SetPolicies($Item.Path, $Policies);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 2019-03-24
    相关资源
    最近更新 更多