Created
July 12, 2016 09:17
-
-
Save jasmin-mistry/9de9daf74cbc1d56a33984f2787ad2ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[string]$server = 'localhost' | |
[string]$serverurl = "http://$server/ReportServer_SQL2014" | |
$proxy = $null | |
# namespace parameter only works for 2010 and not for 2005 but if you get the type after setting up proxy then both works | |
$proxy += New-WebServiceProxy -Uri "$serverurl/ReportService2010.asmx" -UseDefaultCredential ; #-Namespace SSRS.ReportingService2010 | |
# get namespace from the proxy type | |
$type = $proxy.GetType().Namespace | |
#Define Object Types for Subscription property call | |
$ExtensionSettingsDataType = ($type + '.ExtensionSettings') | |
$ActiveStateDataType = ($type + '.ActiveState') | |
$ParmValueDataType = ($type + '.ParameterValue') | |
$extSettings = New-Object ($ExtensionSettingsDataType) | |
# declaring an array | |
$extensionParams = @() | |
$rptParams = @() | |
# read the xml file with all the paramater for creating SSRS Subscription | |
[xml]$xml = Get-Content "C:\temp\ssrs_subscription_input.xml" | |
$xSubscription = $xml.Subscription | |
$xExtensionSettings = $xSubscription.ExtensionSettings | |
# ----- set variable with value available in the xml ----- | |
$report = [string]::Join("", $xSubscription.ReportPath, $xSubscription.ReportName) | |
$desc = $xSubscription.Description | |
$event = $xSubscription.EventType | |
$scheduleXml = $xSubscription.ScheduleXML.'#cdata-section' | |
$extSettings.Extension = $extensionSettings.DeliveryExtension | |
# read the extension setting parameter values | |
$xExtParams = $xExtensionSettings.ParameterValues.ParameterValue | |
foreach ($p in $xExtParams) { | |
$param = New-Object ($ParmValueDataType) | |
$param.Name = $p.Name | |
$param.Value = $p.Value | |
$extensionParams += $param | |
} | |
$extSettings.ParameterValues = $extensionParams | |
# ----- set variable with value available in the xml ----- | |
$paramValues = @() | |
#$paramValue = New-Object ($ParmValueDataType) | |
#$paramValues += $paramValue | |
#$paramValues += $paramValue | |
<# | |
$param = New-Object ($ParmValueDataType) | |
$param.Name = "PASSWORD" | |
$param.Value = "asdfdsaf" #"S@1ram2014" | |
$ExtensionSettings.Value.ParameterValues += $param | |
#> | |
#$report, $extSettings, $desc, $event, $scheduleXml, $paramValues | |
$subid = $proxy.CreateSubscription($report, $extSettings, $desc, $event, $scheduleXml, $paramValues) | |
Write-Host "Susbcription was create with id: '$($subid)'" | |
#$subscriptions += $rs2010.ListSubscriptions($site); # use "/" for default native mode site | |
#Write-Host "----- $server's Subscriptions: " | |
#$subscriptions | select Path, report, Description, Owner, SubscriptionID, lastexecuted, Status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Subscription> | |
<ReportName>SSRS_Report_Name</ReportName> | |
<ReportPath>/ReportFolderName/</ReportPath> | |
<Description>SSRS Subscription Description</Description> | |
<EventType>TimedSubscription</EventType> | |
<ExtensionSettings> | |
<DeliveryExtension>Report Server FileShare</DeliveryExtension> | |
<ParameterValues> | |
<ParameterValue> | |
<Name>PATH</Name> | |
<Value>\\Server\SharedFolder</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>FILENAME</Name> | |
<Value>Report_File_Name</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>FILEEXTN</Name> | |
<Value>True</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>USERNAME</Name> | |
<Value>Domain\Username</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>RENDER_FORMAT</Name> | |
<Value>EXCELOPENXML</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>WRITEMODE</Name> | |
<Value>AutoIncrement</Value> | |
</ParameterValue> | |
<ParameterValue> | |
<Name>PASSWORD</Name> | |
<Value>Somethinghere</Value> | |
</ParameterValue> | |
</ParameterValues> | |
</ExtensionSettings> | |
<ScheduleXML> | |
<![CDATA[ | |
<ScheduleDefinition> | |
<StartDateTime>2016-01-01T01:55:00.000+01:00</StartDateTime> | |
<WeeklyRecurrence> | |
<WeeksInterval>1</WeeksInterval> | |
<DaysOfWeek> | |
<Monday>true</Monday> | |
<Tuesday>true</Tuesday> | |
<Wednesday>false</Wednesday> | |
<Thursday>true</Thursday> | |
<Friday>false</Friday> | |
</DaysOfWeek> | |
</WeeklyRecurrence> | |
</ScheduleDefinition> | |
]]> | |
</ScheduleXML> | |
<ReportParameter> | |
<ParameterValue> | |
<Name></Name> | |
<Value></Value> | |
</ParameterValue> | |
</ReportParameter> | |
</Subscription> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it working for anyone ?