Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 28687

HowTo call ReportService2010.SetCacheOptions() and reference a shared schedule with powershell or C#?

$
0
0

Hi,

i want to programmatically set the "ExecutionOptions" as shown bellow:
-Cache Report, Retire based on a shared Schedule

I managed already to lookup the object of the sharedschedule and want now to pass this in to SetCacheOptions Method of SSRS webservice.
Unfortunately i alway get following error when trying to execute the method:

How can i cast/convert "RS.Schedule" to "RS.ExpirationDefinition"? All i want is to reference the existing sharedSchedule in the SetCacheOptions call..but how to do? Here's the partially working powershell script (You need Powershell V3 installed!):

$reportServerURI = "http://localhost/Reportserver"
$ReportPathWildCard = "/";
$NameSharedSchedule="NeverExpireCache";

# init WS proxy
$reportServerURI2010 = "$reportServerURI/ReportService2010.asmx?WSDL"
$RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI2010 -UseDefaultCredential

#Get Schedule Reference
$NeverExpireSchedule= $rs.ListSchedules([System.Management.Automation.Language.NullString]::Value) | where {$_.Name -eq "$NameSharedSchedule"}
$NeverExpireScheduleID = $NeverExpireSchedule.ScheduleID;
Write-Host "Found Shared Schedule $NameSharedSchedule with id $NeverExpireScheduleID";

#get list of reports
$reports = $RS.ListChildren($ReportPathWildCard,$true) | WHERE {$_.TypeName -eq "Report"}


#process all items
foreach ($report in $reports) {
    $xpath = $report.path
    $xtype = $report.TypeName
    Write-Host "Processing $xtype $xpath"
   
    ##get actual setting
    $s = New-Object("RS.ScheduleDefinitionOrReference")
    $r = $RS.GetExecutionOptions($xpath,[ref] $s);
    Write-Host "--Actual Setting: $r"
    $s = New-Object("RS.ExpirationDefinition")
    $r = $RS.GetCacheOptions($xpath,[ref] $s);
    If ($r) { 
    Write-Host "--Actual Setting: Cache a temporary copy of the report. Expire copy of report on the following schedule " $s.Item.ScheduleID;
    }


    ##SET Cache
    #$o = New-Object("RS.ExpirationDefinition");
    $o = New-Object("RS.ExpirationDefinition");
    $o = $NeverExpireSchedule.Definition
    $r= $RS.SetCacheOptions( $xpath,[System.Management.Automation.Language.NullString]::Value, $NeverExpireSchedule) 
}
  



Viewing all articles
Browse latest Browse all 28687

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>