Powershell Script to Import Subscriptions from CSV file to SSRS

Here is a PowerShell script that can be used to import subscriptions in Microsoft SQL Server Reporting Services (SSRS):


# Load the ReportingServices libraries [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Management.ReportingServices") # Connect to the SSRS server $ssrsServer = "ServerName" $ssrs = New-WebServiceProxy -Uri "http://$ssrsServer/ReportServer/ReportService2010.asmx?WSDL" -Namespace SSRS.ReportingService2010 -UseDefaultCredential # Load the subscriptions from the CSV file $subscriptions = Import-Csv "Subscriptions.csv" # Loop through each subscription in the CSV file foreach ($subscription in $subscriptions) { # Create a new subscription for each entry in the CSV file $newSubscription = New-Object Microsoft.SqlServer.Management.ReportingServices.Execution.ReportExecutionService.Subscription $newSubscription.Path = $subscription.Path $newSubscription.Extension = $subscription.DeliveryExtension $newSubscription.EventType = [Microsoft.SqlServer.Management.ReportingServices.Execution.ReportExecutionService.EventType]::$($subscription.EventType) $newSubscription.Description = $subscription.Description # Create the new subscription $ssrs.CreateSubscription($newSubscription) } # Disconnect from the SSRS server $ssrs = $null

This script starts by loading the ReportingServices libraries and connecting to the SSRS server using the New-WebServiceProxy cmdlet. It then loads the subscriptions from the CSV file using the Import-Csv cmdlet.

The script then loops through each subscription in the CSV file and creates a new subscription using the properties from the CSV file. The properties used to create the subscription include the path of the report, the delivery extension used to send the report, the type of event that triggers the subscription, and the description of the subscription.

The new subscription is created using the CreateSubscription method of the $ssrs object. After creating all the subscriptions, the script disconnects from the SSRS server.

No comments:

Post a Comment