Add one user/group to one specified Reporting Services item

Introduction

This Visual Basic.NET sample script illustrates how to add one user or one group to a SQL Server Reporting Services item by referencing SSRS web services. This script applies to SQL Server Reporting Services 2005, 2008, 2008 R2 and 2012 versions in native mode.

Scenarios

Add a user or a group and grant certain permission on specify item is one question frequently meet in Reporting Services administration. Traditionally, IT professionals can finish this task in Report Manager web site. Actually, using one rss script with variables can also achieve the same effect as using UI.

Script

About how to run this script, please follow below steps:
Step1. On the Start menu, click All Programs, click Accessories, and then click Run. In the Open box, type CMD, and then click OK.
Screenshot:
 
Step2. Run the addpolicy.rss script file.
Command:
rs -i E:\onescript\addpolicy.rss -s servername/reportserver -v GrouporUserName="DomainName\userorgroupname" -v TargetItemPath="/AAA/BB/cc" -v iskeepOriginalPolicy="True" -v RoleName="Browser"
Screenshot:
  
Note: replace the values of the variables with yours.
-i: “E:\onescript\addpolicy.rss”, the addpolicy.rss script file locates in the local path E:\onescript.
-s: “servername/reportserver” is the target report server URL.
GrouporUserName: the user or group name that you would like to add.
TargetItemPath: the target item path that you would like to add the user or group to, it should be one path from the target report server.
iskeepOriginalPolicy: “True”, keep the original policy that existing on the item; “False”, cover the original policy of the item.
RoleName: the role type name that you would like to grant to the user or group.
 
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
Visual Basic
Edit|Remove
'To check if to keep the original policy of the target item Dim originalPermissions() As Policy  
 
IF iskeepOriginalPolicy = "True"Then 
 
originalPermissions = rs.GetPolicies(TargetItemPath,True) 
 
Else  
 
originalPermissions = NothingEnd IF 
 
'Define one list variable to store the original policysDim list AsNew System.Collections.ArrayList(originalPermissions)  
 

Additional Resources

Running a Reporting Services Script File
SetPolicies
Related forum threads:
http://social.technet.microsoft.com/Forums/en-US/sqlreportingservices/thread/92615dd5-b87a-447b-bf5c-75637ac4c716
http://social.technet.microsoft.com/Forums/en-US/sqlreportingservices/thread/d477d1ff-872a-44bd-bb5b-0726e784c9cf
http://social.technet.microsoft.com/Forums/en-US/sqlreportingservices/thread/185a517f-14cc-482a-835a-a80d7a1e93e0