Administering SSRS with PowerShell

tsql2sdayI’ve covered a lot of SSRS security tasks using PowerShell over on SQL Shack where I connect directly using the New-WebServiceProxy command. For T-SQL Tuesday I wanted to do a quick comparison between my original method and the official Reporting Services module and see what else the module offers.

The first thing you’ll want to do is to get the SSRS module using the following command. (You’ll need PowerShellGet if you aren’t using PowerShell 5.0+)

Looking at some basic tasks like retrieving a folder’s contents or a specific item’s security (assuming you have the required access), involves a single line of code. It’s easy to use & provides tool-tips for commands. I’ve installed the module, added my ReportServer URI to a variable and I’m ready to start returning data.

Here’s a few example commands:

Now lets think about the kind of tasks we might want to automate, the data we’d want to collect that would be a nightmare if done manually. This is where PowerShell shines and as I’m writing about, there’s usually several ways to solve the same problem.

Folder level security in Reporting Services

This is something you’d want to see in an audit, before a significant security change or maybe taken as a backup for piece of mind. I do this regularly, even on instances I’ve setup myself. There’s almost always a random user “added for testing” and never removed and using PowerShell is much easier than fishing through every folder manually, with no point in time record of what security looked like.

A nice feature of the Reporting Services module is recursion. A draw back of my existing scripts is having to loop through all the folders in the instance, which means more lines of code.

Simply adding the -Recurse flag will return every item in that instance (unless I restrict by type as shown):

Under the hood, the Reporting Services module has a wealth of abilities built in allowing you to do almost everything with SSRS using PowerShell. There’s also extensive error handling, all of which my “standard Web Service Proxy” example doesn’t cover but even taking that into account, it is SIGNIFICANTLY slower returning the security on all folders. Even when I declared a proxy at the start & referenced this instead of a new connection to the instance for each call to get an item’s security.

Standard Web Service Proxy

Reporting Services Module

Timings

On an instance of 190 folders the direct Web Service Proxy script took 02:30s. On the same instance the Reporting Services module took 04:22s. Both returned a csv file of 1650 individual security roles, covering all folders.

I’ve not dug deeply into what the module is doing with all this time, though I know there are aliases being set and checks for SQL versions, defaults for variables etc. I also have no doubt it is far more robust than my quick, direct script but if you’re looking for data quickly, the module may not always be your best option. Exploring the module however, I find you can quickly and easily retrieve concise metadata with a single command.

Deploying Content

Having recently worked on the deployment of SSRS content through C#, I’m impressed to find how easy it is in PowerShell using the SSRS module.

A single command uploads a report, dataset or data source.

Adding the -WhatIf flag at the end explains exactly what the command will do with the parameters you’ve provided

What if: Performing the operation “Upload from C:\Dropbox\CraigPorteous.com\Average Report Execution Times.rdl to Report Serve
r at /CPorteous/Test” on target “Average Report Execution Times”.

If the destination folder doesn’t exist, you will need to create it first though.

We can even upload the entire contents of a local folder to one in Reporting services

Unfortunately, Write-RsFolderContent doesn’t have an -Overwrite flag so any items that already exist will end in an error.

This command would sit well with Out-RsFolderContent allowing you to export entire folders from SSRS to a local path then re-upload, possibly to a new instance.

Wrap up

There is a lot of great functionality in the SSRS module already with some small additions needed to smooth out processes. The module is constantly being updated & developed so jump over to the GitHub page to check it out & give it a try yourself. Here’s a few ideas that have came to me since playing with it…

  • Update Data Source passwords – This is always a pain where I have a single data access account across multiple data sources & need to use the UI to update them one by one.
  • Deploy content & set perms in a single script.
  • Pull down all reports from an instance to quickly re-populate a Dev instance
  • Configure an RS instance unattended
  • Grant & remove permissions from multiple folders

 

 

You may also like...

Leave a Reply