SSRS 如何使用 Powershell 获取报表缓存选项?
SSRS How to Get Report Cache Options With Powershell?
在 SSRS Web 界面中,如果报告配置为 "Always run this report against pregenerated snapshots",则单击报告并转到管理 --> 缓存后,有一个 缓存快照 部分有一个选项 "Create cache snapshots on a schedule"
我一直在摆弄 PowerShell 并尝试创建一个脚本,找到设置了此选项的所有报告,并输出计划。
我有这个脚本迭代每个报告 "Execution Type" of "Snapshot",但我相信我调用了错误的方法 (GetCacheOptions),因为它 returns 是每项错误:
Clear-Host
$webServiceUrl = 'http://myReportServer.domain.com/reportserver/reportservice2010.asmx?WSDL'
$rs = New-WebServiceProxy -Class 'RS' -Namespace 'RS' -Uri $webServiceUrl -UseDefaultCredential
$reports = $rs.ListChildren("/Some Folder", $true) | Where-Object { $_.TypeName -eq "Report" }
$schedDef = New-Object RS.ScheduleDefinition
$expDef = New-Object RS.ExpirationDefinition
foreach ($report in $reports) {
$execType = $rs.GetExecutionOptions($report.Path, [ref]$schedDef.Item)
if($execType -eq "Snapshot") {
$rs.GetCacheOptions($report.Path, [ref]$expDef.Item)
}
}
有谁知道需要调用什么方法来获取这些信息以及如何调用这个方法(即需要提供什么参数)?
编辑:
根据接受的答案的指导,我能够进行一些编辑(如下),但我没有得到我想要的时间表信息:
.......
....
foreach ($report in $reports) {
$execResult = $rs.GetExecutionOptions($report.Path,
[ref]$ScheduleDefinitionOrReference)
if ($execResult -eq "Snapshot") {
if($ScheduleDefinitionOrReference.Item -is [RS.DailyRecurrence]) {
Write-Host "$($report.Name):" -f Green
Write-Host "`tSchedule Information:" -f Yellow
Write-Host "`t`tEvery $($ScheduleDefinitionOrReference.Item.Daysinterval) Day(s)"
Write-Host "`t`tStart Time: $($ScheduleDefinitionOrReference.StartDateTime)`n"
}
}
您可以使用 ReportingService2010.GetItemHistoryOptions
并将 ItemPath
、out bool KeepExecutionSnapshots
和 out ScheduleDefinitionOrReference
传递给方法。
如果勾选按计划创建缓存快照,ScheduleDefinitionOrReference
将包含 ScheduleDefinition
,否则其值为 NoSchedule
。
例子
$svcUrl = 'http://the-host-name/ReportServer/reportservice2010.asmx'
$svc = New-WebServiceProxy -Class 'RS' -Namespace 'RS' -Uri $svcUrl -UseDefaultCredential
$reports = $svc.ListChildren("/", $true) | Where-Object { $_.TypeName -eq "Report" }
$KeepExecutionSnapshots = $false
$ScheduleDefinitionOrReference = New-Object RS.ScheduleDefinitionOrReference
foreach ($report in $reports) {
$svc.GetItemHistoryOptions($report.Path,
[ref]$KeepExecutionSnapshots,
[ref]$ScheduleDefinitionOrReference)
$report.Path
$ScheduleDefinitionOrReference
}
在 SSRS Web 界面中,如果报告配置为 "Always run this report against pregenerated snapshots",则单击报告并转到管理 --> 缓存后,有一个 缓存快照 部分有一个选项 "Create cache snapshots on a schedule"
我一直在摆弄 PowerShell 并尝试创建一个脚本,找到设置了此选项的所有报告,并输出计划。
我有这个脚本迭代每个报告 "Execution Type" of "Snapshot",但我相信我调用了错误的方法 (GetCacheOptions),因为它 returns 是每项错误:
Clear-Host
$webServiceUrl = 'http://myReportServer.domain.com/reportserver/reportservice2010.asmx?WSDL'
$rs = New-WebServiceProxy -Class 'RS' -Namespace 'RS' -Uri $webServiceUrl -UseDefaultCredential
$reports = $rs.ListChildren("/Some Folder", $true) | Where-Object { $_.TypeName -eq "Report" }
$schedDef = New-Object RS.ScheduleDefinition
$expDef = New-Object RS.ExpirationDefinition
foreach ($report in $reports) {
$execType = $rs.GetExecutionOptions($report.Path, [ref]$schedDef.Item)
if($execType -eq "Snapshot") {
$rs.GetCacheOptions($report.Path, [ref]$expDef.Item)
}
}
有谁知道需要调用什么方法来获取这些信息以及如何调用这个方法(即需要提供什么参数)?
编辑:
根据接受的答案的指导,我能够进行一些编辑(如下),但我没有得到我想要的时间表信息:
.......
....
foreach ($report in $reports) {
$execResult = $rs.GetExecutionOptions($report.Path,
[ref]$ScheduleDefinitionOrReference)
if ($execResult -eq "Snapshot") {
if($ScheduleDefinitionOrReference.Item -is [RS.DailyRecurrence]) {
Write-Host "$($report.Name):" -f Green
Write-Host "`tSchedule Information:" -f Yellow
Write-Host "`t`tEvery $($ScheduleDefinitionOrReference.Item.Daysinterval) Day(s)"
Write-Host "`t`tStart Time: $($ScheduleDefinitionOrReference.StartDateTime)`n"
}
}
您可以使用 ReportingService2010.GetItemHistoryOptions
并将 ItemPath
、out bool KeepExecutionSnapshots
和 out ScheduleDefinitionOrReference
传递给方法。
ScheduleDefinitionOrReference
将包含 ScheduleDefinition
,否则其值为 NoSchedule
。
例子
$svcUrl = 'http://the-host-name/ReportServer/reportservice2010.asmx'
$svc = New-WebServiceProxy -Class 'RS' -Namespace 'RS' -Uri $svcUrl -UseDefaultCredential
$reports = $svc.ListChildren("/", $true) | Where-Object { $_.TypeName -eq "Report" }
$KeepExecutionSnapshots = $false
$ScheduleDefinitionOrReference = New-Object RS.ScheduleDefinitionOrReference
foreach ($report in $reports) {
$svc.GetItemHistoryOptions($report.Path,
[ref]$KeepExecutionSnapshots,
[ref]$ScheduleDefinitionOrReference)
$report.Path
$ScheduleDefinitionOrReference
}