Disable and enable multiple Subscriptions in PBIRS/SSRS 2017

Our Reporting Team wanted to disable all of the actual subscriptions because our production has to be stopped in case of the Coronavirus Pandemie and reports don’t show realistic data. But they want to be able to activate the same reports again later – and not all reports!

Our first „solution“ to disable all of the reports was to send the reports by email
to „/dev/nul“ 😉
Therefore we changed the SMTP Mailserver in the Reporting Services Configuration. Below is a link to a mini PowerShell SMTP Server „Blackhole“ which we tested on the SSRS. Later I’ve found that there doesn’t need to be a SMTP Server running. Changing the entry works without any problem.

The success lasted only one day.
Then the Reporting Team needed to activate some reports again, so our solution doesn’t work anymore.

A Google Search shows up several PowerShell snippets to disable or enable simple reports via the subscription id or do this for all of the reports (Link in the notes at the end of this article). But there is no solution for a huge number of reports (~600 Reports).
BTW: Enabling and disabling Report Subscriptions only works from version 2016 and beyond!

With a litte help from my friend Claudio @ClaudioESSilva I implemented the idea of storing the subscription IDs in a sql table and using them for disabling and enabling all IDs in a loop.

<# 
Name: SSRS enable disable Reports.ps1
Author: Volker Bachmann
Date: 11.4.2020

:
Disable and Enable Reports or their subscription with a list of SubscriptionIDs

#>

Function LogWrite
{
    # simple function for logging to a file.

    Param ([string]$logstring)
   $Logfile=".\enable_disable_reports.log"

   $logstring += " ["
   $logstring += (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
   $logstring += "]"

   Add-content $Logfile -value $logstring
   
}


# $URI="http://<SSRS Server>/ReportServer/ReportService2010.asmx" 
[int]$counter=0


# ############################################################################
# Disable specific Subscriptions, defined in a referenced SQL Table

<# SQL Table Definition and Load

    CREATE TABLE [dbo].[Subscriptions](
    [id] [INT] IDENTITY(1,1) NOT NULL,
    [subscription_id] [UNIQUEIDENTIFIER] NULL
    ) ON [PRIMARY]
    GO

    INSERT INTO Subscriptions (subscription_id)
    VALUES

    ('D0DD9A1C-2393-4529-9F93-85DEC5FCD42F'),
    ('A023E6B9-943E-4A53-806D-1A05A8FBE0A8'),
    ('F28A93D5-FB56-46BE-A057-5B16945728B6');

#>

[string]$serverName = '<SSRS Server>' # ServerName for the list of subscriptionIDs

# connection to the table of subscription ids
$SubscriptionList = (Invoke-SQLCmd -query "select * from [Subscriptions]" -Server $serverName )

# connection to the Reporting Server with actual credentials
$rs2010 = New-WebServiceProxy -Uri $URI -Namespace SSRS.ReportingService2010 -UseDefaultCredential;  

# create new chapter in the logfile
LogWrite  "############# Start disable ###################"

# loop through all subscription ids of the list and disable them
ForEach ($subscription in $SubscriptionList)  
{  
    # Error-handling with a try/catch 
 
try {
    $rs2010.DisableSubscription($subscription.ItemArray[1]);  
        
        write-host "disabled :"  $subscription.ItemArray[1]

        $output = "disabled : "+  $subscription.ItemArray[1]
        LogWrite  $output
    
        $counter ++ # counting the amount of successful disabled subscriptions

    }
catch {
    write-host "Error during disabling of id :"  $subscription.ItemArray[1]

    $output =  "Error during disabling of id : "+  $subscription.ItemArray[1]
    LogWrite  $output
    }    
}# End ForEach

$output =  "=> Amount of disabled Subscription IDs : " 
$output += $counter 
LogWrite  $output

# Chapter End in Log
LogWrite  "############# End disable  ###################"

This was for disabling the subscription IDs – enabling is nearly the same:

# ###################################################################
# Enable specific Subscriptions, defined in a referenced SQL Table
 
# Definition and load of the table see above.

# ServerName for the list of subscription ids
[string]$serverName = '<SSRS Server>' 

# connection to the table of subscription ids
$SubscriptionList = (Invoke-SQLCmd -query "select * from Subscriptions" -Server $serverName )

# connection to the Reporting Server with actual credentials
$rs2010 = New-WebServiceProxy -Uri $URI -Namespace SSRS.ReportingService2010 -UseDefaultCredential;  

# create new chapter in the logfile
Log-Write  "############# Start enable ###################"

# loop through all subscription ids of the list an enable them
ForEach ($subscription in $SubscriptionList)  
{  
    #try/Catch see above
try {
    $rs2010.EnableSubscription($subscription.ItemArray[1]);  

        write-host "enabled :"  $subscription.ItemArray[1]

        $output = "enabled : "+  $subscription.ItemArray[1]
        LogWrite  $output
    
        $counter ++ # count the amount of successful subscriptions
    }
    catch
    {
    write-host "Error enabling id :"  $subscription.ItemArray[1]

    $output = "Error enabling id : "+  $subscription.ItemArray[1]
    LogWrite  $output
    }
} # End ForEach

$output =  "=> Amount of enabled Subscription IDs : "
$output += $counter 
LogWrite $output

# End in Log
LogWrite  "############# End enable ###################"

These two snippets work for me.
Disabling Subscriptions brings up some Errors for me when:

  • Owner of the Subscription is not valid any more -> change Owner
  • Subscription is not a report – it was a Power BI or other subscription
  • In the subscription was an End date set – than the disable didn’t work for me.

Any comments, additions?

Thanks for Reading,
Volker

Notes: Links to documentation from Microsoft:

SMTP Blackhole (German only): https://www.msxfaq.de/tools/sonstige/smtp_blackhole.htm 

Speaking at SQLGrillen 2018

[German version below]

Hello #SQLFamily,

as previously announced I was selected to speak in the Newcomer Track of SQL Grillen 2018.

My first ever session on a SQL Server conference was in German and called „Mission SQL Migration – Aus Blech wird VM“ and was about migrating physical SQL Server to virtual ones.
The important parts were the VMware architecture, guest configuration and how to migrate the whole SQL Server with one single command.

About 20 people were in the room and the session went smooth. Also the demo on a remote server in our company network works like a charme. Because of some deeper discussions about the need of virtualization and the pros and cons, I was not able to show some more of the fantastic dbatools commands I’ve prepared.
So only the Start-DbaMigration was shown and the „Best Practices“ commands like Test-DbaMaxMemory, Test-DbaMaxDop, Test-DbaTempDBConfiguration (…) and the important Invoke-DbaDatabaseUpgrade for upgrading the migrated Databases to the last compatibility level were not shown.

But at the end I finished just in time and I was happy how it works.
I’ve got some direct Feedback from friends and also my mentor Björn Peters (t) who had helped me a lot preparing the session. Thanks a lot!

Hopefully I’ll be able to present on other SQL conferences in the future.

Here is the complete (german) presentation: Mission SQL Migration – Aus Blech wird VM 2018-06-20

Thanks for reading,
Volker


[German]

Hallo # SQLFamily,

Wie bereits angekündigt, wurde ich ausgewählt, im Newcomer Track von SQL Grillen 2018 zu sprechen.

Meine allererste Session auf einer SQL Server-Konferenz war auf Deutsch und hieß „Mission SQL Migration – Aus Blech wird VM“. Es ging darum, physikalsche SQL Server auf virtuelle SQL Server zu migrieren.
Die wichtigsten Teile waren die VMware-Architektur, die Guest-Konfiguration und die Migration des gesamten SQL-Servers mit einem einzigen Befehl.

Ungefähr 20 Leute waren im Raum und die Session lief glatt. Auch die Demo auf einem Remote-Server in unserem Firmennetzwerk funktionierte reibungslos. Aufgrund einiger tiefer gehender Diskussionen über die Notwendigkeit von Virtualisierung und die Vor- und Nachteile, konnte ich einige der fantastischen dbatools-Befehle, die ich vorbereitet hatte, nicht mehr zeigen.
Es wurde also leider nur die eigentliche Migration mit dem Kommando Start-DbaMigration gezeigt und die „Best Practices“ -Befehle wie Test-DbaMaxMemory, Test-DbaMaxDop, Test-DbaTempDBConfiguration (…) und das wichtige Invoke-DbaDatabaseUpgrade für das Upgrade der migrierten Datenbanken auf die letzte Kompatibilitätsstufe wurden aus Zeitmangel leider nicht mehr gezeigt.

Aber am Ende war ich gerade rechtzeitig fertig und ich war glücklich, wie es geklappt hat. Ich habe ein direktes, positives Feedback von Freunden und auch von meinem Mentor Björn Peters (t) erhalten, der mir bei der Vorbereitung der Session sehr geholfen hat. Vielen Dank nochmal dafür!

Ich hoffe auch auf zukünftigen SQL Konferenzen noch als Sprecher vortragen zu können um meine Erkenntnisse und Erfahrungen mit der SQL Community zu teilen.

Hier findet sich noch die Präsentation: Mission SQL Migration – Aus Blech wird VM 2018-06-20

Vielen Dank fürs Lesen,
Volker

Ich spreche @SQLGrillen 2018 – Thema: Mission SQL Migration – Aus Blech wird VM

Zum ersten Mal werde ich bei einer SQL Server Konferenz sprechen!!!
Am kommenden Freitag (22.6.2018) gibt es beim SQLGrillen in Lingen (Ems) einen Newcomer Track. Diesen werde ich direkt um 9:00 Uhr mit meinem Vortrag beginnen:
Mission SQL Migration – Aus Blech wird VM

Darin werde ich von meinem Projekt zur Migration von physikalischen SQL Server in eine VMware Umgebung berichten. Grundlage sind unter anderem die Blogbeiträge auf diesem Blog mit dem entsprechenden Tag: https://blog.volkerbachmann.de/tag/sql-on-vmware/

Sehen wir uns dort?

Viele Grüße,
Volker

 

 

TSQL2sday #94 – SQL Server Best Practices Test with PowerShell dbatools #tsql2sday

T-SQL Tuesday #94 – Lets get all Posh!

Rob Sewell aka sqldbawithabeard (b|t) hosts this month T-SQL Tuesday and surprisingly his subject is PowerShell.

I will describe what I’ll use for testing against Best Practices Commands for SQL Server.

I got in contact with PowerShell some years ago, but was not satisfied with what needs to be done before maintaining SQL Server.

Meanwhile Microsoft has done a lot more and with the contribution from several PowerShell Experts and MVPs as Chrissy LeMaire, Claudio Silva, Rob Sewell, Constantine Kokkinos and many more, there is a module created that helps to maintain SQL Server 2005+. This is called dbatools and the website can be reached at https://dbatools.io. The Project is hosted on Github and using the commands is totally free of charge!

The community has grown to over 50 contributors and over 200 SQL Server best practices, administration and migration commands. An Overview of the commands can be found here: https://dbatools.io/functions/

Now I will describe some of the dbatools commands to Test our SQL Server against Best Practices mentioned by SQL Server Experts. You can find all of the information and Links in the description to the commands.

  • Max Memory
    • This tests the actual max memory setting against the recommended setting.
    • Test-DbaMaxMemory -SqlServer sqlserver01
      # command to set the max memory to the recommended
      Set-DbaMaxMemory -SqlServer sqlserver01
      # or to a fix value of 2 GB
      Set-DbaMaxMemory -SqlInstance sqlserver01 -MaxMb 2048
  • TempDB
    • with SQL Server 2016 you get the option to configure the TempDB Configuration during installation, with this commands you can control and fix it.
    • Test-DbaTempDbConfiguration
    • Evaluates tempdb against a set of rules to match best practices.
      The rules are:
      – Is Trace Flag 1118 enabled (See KB328551).
      – File Count: Does the count of data files in tempdb match the number of logical cores, up to 8.
      – File Growth: Are any files set to have percentage growth, as best practice is all files have an explicit growth value.
      – File Location: Is tempdb located on the C:\? Best practice says to locate it elsewhere.
      – File MaxSize Set(optional): Do any files have a max size value? Max size could cause tempdb problems if it isn’t allowed to grow.
    • Test-DbaTempDbConfiguration(Screenshot from dbatools.io – my configurations are all fine 🙂 )
    • The right configuration can be set by using the corresponding Set- command
  • Disk-Configuration
    • Test-DbaDiskAlignment
      • This command verifies that your non-dynamic disks are aligned according to physical requirements.
      • Test-DbaDiskAlignment -ComputerName sqlserver01| Format-Table
      • Test-DbaDiskAlignment
    • Test-DbaDiskAllocation
      • Checks all disks on a computer to see if they are formatted to 64k, the best practice for SQL Server disks
      • Test-DbaDiskAllocation -ComputerName sqlserver01 | Format-Table
      • Test-DbaDiskAllocation
  • PowerPlan
    • Test-DbaPowerPlan
      • The Servers Powerplan should be set to High Performance on every SQL Server
      • Test-DbaPowerPlan -ComputerName sqlserver01
      • Test-DbaPowerPlan

 

  • SPN
    • We use DNS CNAMEs for referring to our SQL Server (2). We need to adjust the SPN Settings manually. That is easy with these commands:
      Get-DbaSpn / Set-DbaSPN
  • SQL Server Name
    • We created a Single VM template where all SQL Server are created from. With CPU, Memory and Disk Layout.
    • After creating a new VM out of the template the Server Name changes but not the SQL Server Name internally. Help comes again with dbatools command: Repair-DbaServerName
      Works fine for me!

Theses are the commands we use often in our environment, there are many more to choose from on the dbatools website.

Thanks to Rob for hosting this month T-SQL Tuesday and thanks to all other attendees to convince me writing a blog post. Thanks also to Adam Bertram who chooses me writing for #PSBlogWeek. You all can attend until this friday (2017-09-15). http://psblogweek.com/

Thanks for Reading,
Volker