[SharePoint 2013] Subscribe report within SharePoint mode

 1 param([string]$path, [string]$fileName, [string]$storage)
 2 
 3 $description = "Save in $storage as $fileName."
 4 
 5 $matchData31 = '<?xml version="1.0" encoding="utf-16" standalone="yes"?><ScheduleDefinition xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><StartDateTime xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">2017-01-01T23:00:00.000+01:00</StartDateTime><MonthlyRecurrence xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer"><Days>31</Days><MonthsOfYear><January>true</January><March>true</March><May>true</May><July>true</July><August>true</August><October>true</October><December>true</December></MonthsOfYear></MonthlyRecurrence></ScheduleDefinition>'
 6 
 7 $matchData30 = '<?xml version="1.0" encoding="utf-16" standalone="yes"?><ScheduleDefinition xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><StartDateTime xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">2017-01-01T23:00:00.000+01:00</StartDateTime><MonthlyRecurrence xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer"><Days>30</Days><MonthsOfYear><April>true</April><June>true</June><September>true</September><November>true</November></MonthsOfYear></MonthlyRecurrence></ScheduleDefinition>'
 8 
 9 $matchData28 = '<?xml version="1.0" encoding="utf-16" standalone="yes"?><ScheduleDefinition xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><StartDateTime xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer">2017-01-01T23:00:00.000+01:00</StartDateTime><MonthlyRecurrence xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer"><Days>28</Days><MonthsOfYear><February>true</February></MonthsOfYear></MonthlyRecurrence></ScheduleDefinition>'
10 
11 $eventType = "TimedSubscription"
12 $extension = "Report Server DocumentLibrary"
13 $webServiceUri = "http://server/_vti_bin/ReportServer/ReportService2010.asmx"
14 
15 $rs2010 = New-WebServiceProxy -Uri $webServiceUri -Namespace SSRS.ReportingService2010 -UseDefaultCredential
16 
17 $parameters = New-Object -TypeName System.Collections.Generic.List[SSRS.ReportingService2010.ParameterValue]
18 $deliverySettings = New-Object -TypeName SSRS.ReportingService2010.ExtensionSettings
19 $parameterValues = New-Object -TypeName System.Collections.Generic.List[SSRS.ReportingService2010.ParameterValueOrFieldReference]
20 
21 $parameterFileName = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
22 $parameterFileName.Name = "FILENAME"
23 $parameterFileName.Value = $fileName
24 $parameterValues.Add($parameterFileName)
25 
26 $parameterFileExtn = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
27 $parameterFileExtn.Name = "FILEEXTN"
28 $parameterFileExtn.Value = $true
29 $parameterValues.Add($parameterFileExtn)
30 
31 $parameterTitle = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
32 $parameterTitle.Name = "TITLE"
33 $parameterTitle.Value = $fileName
34 $parameterValues.Add($parameterTitle)
35 
36 $parameterFormat = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
37 $parameterFormat.Name = "RENDER_FORMAT"
38 $parameterFormat.Value = "EXCELOPENXML"
39 $parameterValues.Add($parameterFormat)
40 
41 $parameterMode = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
42 $parameterMode.Name = "WRITEMODE"
43 $parameterMode.Value = "Overwrite"
44 $parameterValues.Add($parameterMode)
45 
46 $parameterAutoCopy = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
47 $parameterAutoCopy.Name = "AUTOCOPY"
48 $parameterAutoCopy.Value = $false
49 $parameterValues.Add($parameterAutoCopy)
50 
51 $parameterPath = New-Object -TypeName SSRS.ReportingService2010.ParameterValue
52 $parameterPath.Name = "PATH"
53 $parameterPath.Value = $storage
54 $parameterValues.Add($parameterPath)
55 
56 $deliverySettings.Extension = $extension
57 $deliverySettings.ParameterValues = $parameterValues.ToArray()
58 
59 $subscriptions = $rs2010.ListSubscriptions($path)
60 
61 if($subscriptions.Count -eq 0){
62     $subscription31 = $rs2010.CreateSubscription($path, $deliverySettings, $description, $eventType, $matchData31, $parameters.ToArray())
63     Write-Host $subscription31
64     
65     $subscription30 = $rs2010.CreateSubscription($path, $deliverySettings, $description, $eventType, $matchData30, $parameters.ToArray())
66     Write-Host $subscription30
67     
68     $subscription28 = $rs2010.CreateSubscription($path, $deliverySettings, $description, $eventType, $matchData28, $parameters.ToArray())
69 
70     Write-Host $subscription28
71 }

 

posted @ 2017-01-06 14:02  一只小小菜鸟  阅读(291)  评论(0编辑  收藏  举报