In my post two days ago on silently installing SQL Server 2017 Reporting Services (SSRS 2017), I just provided the most basic information on configuration. In fact, after installing SSRS 2017, it will be completely unconfigured. Configuration can be done using the Reporting Service Configuration Manager GUI. In my case, the configuration needs to be automated, so I use PowerShell.
I have posted my complete PowerShell script for configuration of SSRS 2017 to a GitHub Gist. It’s embedded below. The script itself has comments that will hopefully allow you to follow the flow, but here is a quick overview of the different steps:
- Get a WMI object with the configuration settings for the SSRS 2017 instance.
- Get a SQL script to create the ReportServer and ReportServerTempDB databases.
- Establish a connection to the default SQL Server instance on the same machine.
- Execute the SQL script.
- Get and execute a second SQL script, this time to set the permissions for the SSRS 2017 service account.
- Set the SSRS database connection to this newly created database.
- Configure the virtual directory name and URL of the web service.
- Configure the virtual directory name and URL of the report manager web app.
- Initialize the report server with encryption for sensitive data.
- Restart the service.
- Output the new configuration.
Note: I expect this script will also work with SQL Server 2016 Reporting Services. It will not work with earlier versions without changing the name of the Report Manager web application to ReportManager.
<# | |
#> | |
function Get-ConfigSet() | |
{ | |
return Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer\RS_SSRS\v14\Admin" ` | |
-class MSReportServer_ConfigurationSetting -ComputerName localhost | |
} | |
# Allow importing of sqlps module | |
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force | |
# Retrieve the current configuration | |
$configset = Get-ConfigSet | |
$configset | |
If (! $configset.IsInitialized) | |
{ | |
# Get the ReportServer and ReportServerTempDB creation script | |
[string]$dbscript = $configset.GenerateDatabaseCreationScript("ReportServer", 1033, $false).Script | |
# Import the SQL Server PowerShell module | |
Import-Module sqlps -DisableNameChecking | Out-Null | |
# Establish a connection to the database server (localhost) | |
$conn = New-Object Microsoft.SqlServer.Management.Common.ServerConnection -ArgumentList $env:ComputerName | |
$conn.ApplicationName = "SSRS Configuration Script" | |
$conn.StatementTimeout = 0 | |
$conn.Connect() | |
$smo = New-Object Microsoft.SqlServer.Management.Smo.Server -ArgumentList $conn | |
# Create the ReportServer and ReportServerTempDB databases | |
$db = $smo.Databases["master"] | |
$db.ExecuteNonQuery($dbscript) | |
# Set permissions for the databases | |
$dbscript = $configset.GenerateDatabaseRightsScript($configset.WindowsServiceIdentityConfigured, "ReportServer", $false, $true).Script | |
$db.ExecuteNonQuery($dbscript) | |
# Set the database connection info | |
$configset.SetDatabaseConnection("(local)", "ReportServer", 2, "", "") | |
$configset.SetVirtualDirectory("ReportServerWebService", "ReportServer", 1033) | |
$configset.ReserveURL("ReportServerWebService", "http://+:80", 1033) | |
# For SSRS 2016-2017 only, older versions have a different name | |
$configset.SetVirtualDirectory("ReportServerWebApp", "Reports", 1033) | |
$configset.ReserveURL("ReportServerWebApp", "http://+:80", 1033) | |
$configset.InitializeReportServer($configset.InstallationID) | |
# Re-start services? | |
$configset.SetServiceState($false, $false, $false) | |
Restart-Service $configset.ServiceName | |
$configset.SetServiceState($true, $true, $true) | |
# Update the current configuration | |
$configset = Get-ConfigSet | |
# Output to screen | |
$configset.IsReportManagerEnabled | |
$configset.IsInitialized | |
$configset.IsWebServiceEnabled | |
$configset.IsWindowsServiceEnabled | |
$configset.ListReportServersInDatabase() | |
$configset.ListReservedUrls(); | |
$inst = Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer\RS_SSRS\v14" ` | |
-class MSReportServer_Instance -ComputerName localhost | |
$inst.GetReportServerUrls() | |
} |
I dont see the code anywhere? Is it posted?
G:
Yes, it is. Do you not see it below the post?
Maybe you have a script or ad blocker that’s blocking the embed? Here is a direct link to the gist: https://gist.github.com/SvenAelterman/f2fd058bf3a8aa6f37ac69e5d5dd2511
How to connect to already created database ?
Hi,
Thanks for reading.
I haven’t had that need, so I am afraid I don’t have a script handy for it. Maybe another reader will?
Sven
Hi Sven
I did an automated install of SSRS 2017 and the Get-WmiObject resturn ‘Invalid Namespace’. Any ideas?
When do you receive that exactly?
Oh, silly of me. I realize now there’s only one Get-WmiObject call. You did install SSRS 2017 on that same system?
Hi Sven,
The installation hadn’t completed properly. I enabled .netFx35 feature, reinstalled SSRS (on a clean machine) and added the following line before the call to Get-Configset:
$env:PSModulePath = $env:PSModulePath + “;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules”
All works great now.
Hi Sven
Many thanks for this! I’ve used it to set up SSRS in a docker container and it works great!
source on github.com/phola/SSRS-Docker (credit and link back to this article are in the readme)
cheers, Geoff
Hi Geoff, great to read that you were able to leverage this script! Thanks for the linkback also.
Hi Sven, this script has made my lite-touch sccm configuration even lighter (lite-r).
One question, is it possible to change the service account that is used, so it is not using the Virtual Service Account and instead uses my own domain account created specifically? This also is reflected in the “Current Report Server Database Credential” whereby the end result from running your script shows the Login name as: “NT SERVICE\SQLServerReportingServices”, and i’d rather this be the domain account I created specifically.
If you could provide any guidance here, that’d be great. Thanks.
Neil, my hunch is that it is possible, but I haven’t researched how to do that.
Hi Sven,
I just downloaded the script from GitHub and attempted to run it on my SQL server with RS installed. When ran the script appears to do nothing and comes immediately back to a PS prompt. Is there any PS module we have to import first?
Was this Windows PowerShell? Explicitly importing a module shouldn’t be required.
Hello JC, you might be running against RS V15 and this solution appears to be using V14.
Sven,
Have you thought about doing the same thing using CIM commandlets wtih WMI being deprecated…
Hi Sven,
I am testing and so far it is what i actually need to make my script automated, but i was wondering when i use this : $configset.CreateSSLCertificateBinding(‘ReportServerWebService’,($SSLList.CertificateHash)[0],’192.168.10.4′,443,1033) for example, it does add the name of the cert plus the IP, but one thing i noticed is that it doesn’t exactly do the commit of it until i go check it on the GUI and see if it is there then press okay. Is there a way of committing it or is it normal like that and it will be recognized that way ?
Thank you in advance.
David, are you calling SetServiceState after and restarting the service?
No i didn’t, thank you very much.
Now just for curiosity the moment that the information needed was inserted, it won’t do the commit by itself right ?
That’s correct, it’s like the GUI where you have to click Apply to make it stick.
Hi Sven,
I have tested your script and it just works perfectly. I have one question though… What do I have to change in case I want to SSRS Instance not to be called “SSRS” but having a different name to fit to my naming standard, e.g. R01.
Arne, it would seem that the instance name is set at installation time. You would need to set the name of the instance then.
Can you please share some snippet or thoughts on how to change the ssrs 2019 instance name? Not able to find any parameter to specify the instance name on installation setup (UI/CMD). Thanks in advance.
Hi Sven,
I’ve tried running the above script it was working fine as admin but i am trying to automate the env using packer or either terraform at the run time it was throwing the error
return Get-WmiObject -namespace “root\Microsoft\SqlServer\ReportS …
==> googlecompute: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
googlecompute: UserPolicy Undefined
==> googlecompute: + CategoryInfo : InvalidArgument: (:) [Get-WmiObject], ManagementException
==> googlecompute: + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Can u please help me out. I’ve tried several things like elevating powershell internally and as well as in packer command as well but none of it works. any workaround to run the powershell script as admin or to get rid of the error
I am sorry, I have no experience with GCP or with Terraform to be able to assist. Maybe someone else reading this can.