Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a user with a role to SSRS report


In this recipe, we will add a user with a few roles to SSRS.

Getting ready

In this recipe, we will add QUERYWORKS\tstark as a browser and Content Manager to the customer list report.

For your environment, you can identify a user you want to add to an existing report and which roles you want to assign to them.

How to do it...

Let's explore the code required to add a user with a role to SSRS:

  1. Open PowerShell ISE as an administrator.

  2. Add the following script and run it:

    $reportServerUri  = "http://localhost/ReportServer/ReportService2010.asmx"
    $proxy = New-WebServiceProxy -Uri $reportServerUri -UseDefaultCredential
    $type = $Proxy.GetType().Namespace
    
    $itemPath = "/Customer Reports/Customer List"
    
    #this will hold all the group/users for a report
    $newPolicies = @()
    $inherit = $null
    
    #list current report users
    $proxy.GetPolicies($itemPath, [ref]$inherit)
     
    #NOTE that when we change policies, it will 
    #automatically break inheritance
    #ALSO NOTE that when you programmatically...