Last active
July 11, 2017 16:27
-
-
Save crshnbrn66/40c6be436e7c2e69b4de5cd625ce0902 to your computer and use it in GitHub Desktop.
This file contains 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
param | |
( | |
[String] [Parameter(Mandatory)] | |
$SolutionFile, | |
#this is the evironment that is in the Solution config to read where things need to go (TEST/DEV/QA/Prodution) | |
#for example - C:\tfs2013\Test Automated Deployment Sharepoint.rptproj | |
[string] [Parameter(Mandatory)] $Environment, | |
#this is the name of the Datasource as it exists in Sharepoint without the .rsds extension | |
[string] [Parameter(Mandatory)] $DataSource, | |
#This is the connection string that will be set for the report data source. | |
#this is only necessary if this is the first time the reports are being deployed. | |
[string] [Parameter(Mandatory)] $connectString, | |
#the username that the Datasource will run under | |
#defaults to the user that this script is running under | |
[string] [Parameter(Mandatory)] $username = "$([environment]::UserDomainName)\$([environment]::Username)", | |
[string] [Parameter(Mandatory)] $Password = 'password', | |
[string] $reportExtension = '*.rdl', | |
[string] $setDataSourceOnly = $false, | |
[string] $setCache = $false, | |
[string] $cacheValue = '30', | |
[string] $cacheFiles = '', | |
[string] $datasetFilter = '.rsd' | |
) | |
write-output "__________________________________________________________________" | |
write-output "SolutionFile:`t`t$solutionFile" | |
Write-output "Environment: `t`t$environment" | |
write-output "Datasource: `t`t$datasource" | |
write-output "Connection String: `t`t$connectString" | |
write-output "Username: `t`t$username" | |
write-output "Password is not Null: `t`t$($password -ne $null)" | |
write-output "reportextension: `t`t$reportExtension" | |
write-output "SetDatasourceOnly: `t`t$setDataSourceOnly" | |
Write-Output "SetCache: `t`t$setCache" | |
Write-Output "CacheValue: `t`t$cacheValue" | |
Write-Output "CacheFiles: `t`t$($cacheFiles)" | |
Write-Output "datasetFilter: `t`t$($datasetFilter)" | |
write-output "__________________________________________________________________" | |
write-verbose 'fix to set the variable for the setting of the datasource.' | |
if ($setDatasourceonly -eq 'true') | |
{$setdatasourceonly = $true } | |
else | |
{$setdatasourceonly = $false} | |
if ($setCache -eq 'true') | |
{$setCache = $true} | |
else | |
{$setCache = $false} | |
if ($MyInvocation.MyCommand.Path) | |
{ | |
$scriptpath = $MyInvocation.MyCommand.Path | |
$d = Split-Path $scriptpath | |
write-output -InputObject "Script Directory: `t`t$D" | |
import-module "$d\sqlreporting.psd1" -DisableNameChecking -Force | |
import-module "$d\subscriptions.psm1" -Force | |
} | |
else | |
{ | |
import-module .\sqlreporting.psd1 -DisableNameChecking -Force | |
import-module ".\subscriptions.psm1" -Force | |
} | |
# | |
if (test-path $solutionfile -pathtype Leaf) | |
{ | |
$reportPath = (get-item $solutionfile).DirectoryName | |
[xml]$x = get-content $solutionfile | |
$test = ($x.Project.Configurations.configuration |Where-Object {$_.name -eq $environment}).options | |
$hasSubscriptions = "$(((get-item $reportPath).Parent).FullName)\$((Get-Item $reportPath).Name).subs" | |
if (Test-Is2013SharepointUrl $test.targetServerUrl ) | |
{ | |
$sharepoint = $true | |
$webservice = [System.Net.WebUtility]::UrlDecode(([System.Net.WebUtility]::HtmlDecode("$($test.TargetServerURL)/_vti_bin/ReportServer/ReportService2010.asmx"))) | |
} | |
else | |
{ | |
$u = [uri] $test.targetServerUrl | |
$webservice = $u -replace ($u.PathAndQuery), '/ReportServer/ReportService2010.asmx' | |
$sharepoint = $false | |
} | |
Write-output "webservice: `t`t$webservice" | |
$dataSourceTarget = [System.Net.WebUtility]::UrlDecode(([System.Net.WebUtility]::HtmlDecode($test.TargetDataSourceFolder))) | |
write-output "datasourceTarget: `t`t$datasourceTarget" | |
$documentLibrary = [System.Net.WebUtility]::UrlDecode(([System.Net.WebUtility]::HtmlDecode($test.TargetFolder))) | |
write-output "DocumentLibrary: `t`t$documentLibrary" | |
$d = Get-ChildItem "$reportPath\$datasource*.rds" | |
$dataSourceName = $d.name -replace $d.Extension, '' #remove the extension from the reportdatasource physical filename. | |
if ($x.project.DataSets.ProjectItem) | |
{ | |
$dataSets = $x.project.DataSets.ProjectItem | |
} | |
else {$dataSets = $null} | |
if ($cacheFiles -match "`r`n") | |
{ | |
Write-Output "CRLF Detected" | |
[string[]]$cacheFiles2Set = $cacheFiles -split "`r`n" | |
} | |
elseif ($cacheFiles -match "`n") | |
{ | |
Write-Output "New line detected" | |
[string[]]$cacheFiles2Set = $cacheFiles -split "`n" | |
} | |
else | |
{ | |
[string[]]$cacheFiles2Set = $cacheFiles -split ',' | |
} | |
$cache = @() | |
foreach ($cacheitem in $cacheFiles2Set) | |
{ | |
$Split = $cacheItem -split ',' | |
if ($Split.count -gt 1) | |
{ | |
$cFile = ($split[0].trimstart()).trimend() | |
$cache += [pscustomobject]@{'CacheFile' = $cfile | |
'minutes' = $Split[1] | |
} | |
} | |
else | |
{ | |
$cFile = ($split[0].trimstart()).trimend() | |
$cache += [pscustomobject]@{'CacheFile' = $cfile | |
'minutes' = $cacheValue | |
} | |
} | |
} | |
if ($dataSets) | |
{ | |
write-output "DataSetNames: `t`t$(($DataSets.name -replace '.rsd', '' ) -join ",")" | |
#$dataSetnames = $DataSets.name | |
$TargetDatasetFolder = [System.Net.WebUtility]::UrlDecode(([System.Net.WebUtility]::HtmlDecode($test.TargetDatasetFolder))) | |
write-output "TargetDatasetFolder: `t`t$TargetDatasetFolder" | |
} | |
############################# integrated SSRS Deployment in first if ############################ | |
if ($sharepoint) # this is to tell the script that we are deploying to sharepoint | |
{ | |
$results = Deploy-SharepointReports -datasource $DataSource -documentLibrary $documentlibrary -dataSourceTarget $datasourceTarget -webservice $webservice -username $username -password $password -datasets $datasets -datasetFilter $datasetfilter -TargetDatasetFolder $targetDataSetFolder -reportPath $reportPath -reportExtension $reportExtension -connectString $connectString -setDatasourceOnly $setDatasourceOnly -cachefiles2Set $cache | |
Write-Output $results | |
} | |
############################# native SSRS Deployment in below here ############################## | |
else #Native SSRS deployment falls in here | |
{ | |
$results = Deploy-NativeSSRS -datasource $DataSource -documentLibrary $documentlibrary -dataSourceTarget $datasourceTarget -webservice $webservice -username $username -password $password -datasets $datasets -datasetFilter $datasetfilter -TargetDatasetFolder $targetDataSetFolder -reportPath $reportPath -reportExtension $reportExtension -connectString $connectString -setDatasourceOnly $setDatasourceOnly -cachefiles2Set $cache | |
Write-Output $results | |
} | |
Write-Output $results | |
write-output 'Checking for Subscriptions' | |
if (test-path $hasSubscriptions) | |
{ | |
Push-Location | |
$reportFilter = "*.config" | |
write-output "__________________________________________________________________" | |
Write-Output " This Project has Data Driven Subscriptions updating .... " | |
Write-Output "Documentlibrary: `t`t$documentLibrary" | |
Write-Output "Webservice: `t`t$webservice" | |
Write-Output "Subscription Directory: `t`t$hasSubscriptions" | |
Write-Output "Subscription FileEXT: `t`t$reportFilter" | |
write-output "__________________________________________________________________" | |
$ssrsproxy = New-WebServiceProxy -uri $webservice -UseDefaultCredential -namespace 'SSRSProxy' -class 'ReportService2010' | |
if ( (Get-CustomPowerShellClasses).name -ne 'ssrsobject') | |
{ | |
Write-Verbose "Check to make sure the proxy hasn't already been created" | |
try | |
{ | |
. Invoke-SSRSobject | |
} | |
catch | |
{ | |
Write-Output "Check the $proxy address" | |
break | |
} | |
} | |
else | |
{ | |
Throw "This Script can only execute once because of the dependency on an object [ssrsobject]" | |
break | |
} | |
write-verbose "Checking to see if our object has already been created once if it has we don't want to create it again or the object won't be 'findable'" | |
$currentSubscriptions = get-subscriptions -ssrsproxy $ssrsproxy -site $documentLibrary -DataDriven | |
$sourceSubscriptions = New-DeserializedSSRSObject -path $hasSubscriptions -filter $reportFilter | |
write-output "______________Subscription Removal________________________________" | |
foreach ($sub in $currentSubscriptions) | |
{ | |
if ($sourceSubscriptions | Where-Object {$_.description -eq $sub.description}) | |
{ | |
Write-Verbose "Found the same subscription will delete it in the destination to allow for a re-create" | |
write-verbose "delete $($subscription.subscription.SubscriptionID)" | |
Remove-DatadrivenSubscription -ssrsproxy $ssrsproxy -subscriptionid $sub.subscription.subscriptionid | |
Write-Output "Removed Subscription $($sub.description)" | |
} | |
} | |
write-output "__________________________________________________________________" | |
write-output "______________Subscription Adds__________________________________" | |
foreach ($sub in $sourceSubscriptions) | |
{ | |
Write-Verbose "Creating new subscription for $($sub.description)" | |
try | |
{ | |
Write-Output "Attempting to create Subscripion $($sub.description)" | |
$status = New-DataDrivenSubscription -ssrsproxy $ssrsproxy -reportObject $sub -destination $documentLibrary | |
write-output "Added $($sub.description) from $($sub.subscription.path) $status" | |
} | |
Catch | |
{ | |
"Error was $_" | |
$line = $_.InvocationInfo.ScriptLineNumber | |
"Error was in Line $line ------ Exiting" | |
Break | |
} | |
#$s += $status | |
#Write-Output "Created Subscription $($sub.description) datasource and id $status" | |
} | |
write-output "__________________________________________________________________" | |
Pop-Location | |
} | |
} | |
else | |
{ | |
Throw "SolutionFile cannot be blank or a directory $solutionFile" | |
} | |
This file contains 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
#requires -version 5.0 | |
function Get-DataDrivenSubscriptionProperties | |
{ | |
param([object] $Subscription, | |
[object]$ssrsproxy) | |
$ssrsobject = [SSRSObject]::New() | |
$sid = $Subscription.SubscriptionID | |
$ddextensionSettings = $ddDataRetrievalPlan = $ddDescription = $ddactive = $ddstatus = $ddeventtype = $ddmatchdata = $ddparameters = $Null | |
$ddOwner = $ssrsproxy.GetDataDrivenSubscriptionProperties($sid, [ref]$ddextensionSettings, [ref]$ddDataRetrievalPlan` | |
, [ref]$ddDescription, [ref]$ddactive, [ref]$ddstatus, [ref]$ddeventtype, [ref]$ddmatchdata, [ref]$ddparameters) | |
$ssrsobject.subscription = $Subscription | |
$ssrsobject.Owner = $ddOwner | |
$ssrsobject.ExtensionSettings = $ddextensionSettings | |
$ssrsobject.Description = $ddDescription | |
$ssrsobject.DataRetrievalPlan = $ddDataRetrievalPlan | |
$ssrsobject.Active = $ddactive | |
$ssrsobject.Status = $ddstatus | |
$ssrsobject.EventType = $ddeventtype | |
$ssrsobject.MatchData = $ddmatchdata | |
$ssrsobject.Parameters = $ddparameters | |
$ssrsobject | |
<# [PSCustomObject]@{ | |
'Owner' = $ddOwner | |
'extensionSettings' = $ddextensionSettings | |
'DataRetrievalPlan' = $ddDataRetrievalPlan | |
'Description' = $ddDescription | |
'active' = $ddactive | |
'status' =$ddstatus | |
'eventtype' =$ddeventtype | |
'matchdata' = $ddmatchdata | |
'parameters' = $ddparameters | |
} #> | |
} | |
function Get-SubscriptionProperties | |
{ | |
param([string]$Subscription, | |
[object]$ssrsproxy) | |
$subextensionSettings = $subDataRetrievalPlan = $subDescription = $subactive = $substatus = $subeventtype = $submatchdata = $subparameters = $Null | |
$subOwner = $ssrsproxy.GetSubscriptionProperties($subscription.SubscriptionID, [ref]$subextensionSettings, [ref]$subDescription, [ref]$subactive, [ref]$substatus, [ref]$subeventtype, [ref]$submatchdata, [ref]$subparameters) | |
$ssrsobject = [SSRSObject]::New() | |
$ssrsobject.subscription = $Subscription | |
$ssrsobject.Owner = $subOwner | |
$ssrsobject.ExtensionSettings = $subextensionSettings | |
$ssrsobject.Description = $subDescription | |
$ssrsobject.DataRetrievalPlan = $subDataRetrievalPlan | |
$ssrsobject.Active = $subactive | |
$ssrsobject.Status = $substatus | |
$ssrsobject.EventType = $subeventtype | |
$ssrsobject.MatchData = $submatchdata | |
$ssrsobject.Parameters = $subparameters | |
<# | |
[PSCustomObject]@{ | |
'Owner' = $subOwner | |
'extensionSettings' = $subextensionSettings | |
'Description' = $subDescription | |
'active' = $subactive | |
'status' =$substatus | |
'eventtype' =$subeventtype | |
'matchdata' = $submatchdata | |
'parameters' = $subparameters | |
} | |
#> | |
} | |
function Get-Subscriptions | |
{ | |
#Returns a nested object with each | |
param([object]$ssrsproxy, [string]$site, [switch]$DataDriven) | |
#write-verbose 'Path to where the reports are must be specified to get the subscriptions you want.. Root (/) does not seem to get everything' | |
$items = $ssrsproxy.ListChildren($site, $true) | Where-Object {$_.typename -eq 'report'} | |
$subprops = $ddProps = @() | |
foreach ($item in $items) | |
{ | |
$subs = $ssrsproxy.ListSubscriptions($item.path) | |
write-verbose "found $($subs.count) subscriptions for $($item.Name)" | |
if ($subs) | |
{ | |
foreach ($sub in $subs) | |
{ | |
if ($sub.isdatadriven -eq 'true') | |
{ | |
$ddProps += Get-DataDrivenSubscriptionProperties -subscription $sub -ssrsproxy $ssrsproxy | |
} | |
elseif (-not $DataDriven) | |
{ | |
$subProps += Get-SubscriptionProperties -subscriptionid $sub -ssrsproxy $ssrsproxy | |
} | |
} | |
} | |
} | |
if ($DataDriven) | |
{$ddProps} | |
else | |
{ | |
$subprops | |
} | |
} | |
function New-XMLSubscriptionfile | |
{ | |
[CmdletBinding()] | |
[Alias()] | |
param([psobject]$subscriptionObject, [string]$path, [string]$extension = '.xml') | |
if (test-path $path -PathType Leaf) | |
{ | |
$path = split-path $path | |
} | |
if (-not(test-path $path)) | |
{ | |
mkdir $path | |
} | |
foreach ($sub in $subscriptionObject) | |
{ | |
$reportName = (($sub.subscription.report).split('.'))[0] | |
$filename = "$path\$reportName$extension" | |
$sub | Export-Clixml -Depth 100 -path $filename | |
} | |
} | |
function New-JsonSubscriptionFile | |
{ | |
[CmdletBinding()] | |
[Alias()] | |
param([psobject]$subscriptionObject, [string]$path) | |
if (test-path $path -PathType Leaf) | |
{ | |
$path = split-path $path | |
} | |
if (-not(test-path $path)) | |
{ | |
mkdir $path | |
} | |
foreach ($sub in $subscriptionObject) | |
{ | |
$reportName = (($sub.subscription.report).split('.'))[0] | |
$filename = "$path\$reportName.json" | |
$sub | convertto-json -Depth 100 | out-file $filename | |
} | |
} | |
Function Export-DataDrivenSubscriptions | |
{ | |
param([object]$ssrsproxy, [string]$site, [string]$path, [switch]$json, [string]$extension) | |
$subs = get-subscriptions -ssrsproxy $ssrsproxy -site $site -DataDriven | |
if ($json) | |
{New-JsonSubscriptionFile -subscriptionObject $subs -path $path -extension $extension} | |
else | |
{New-XMLSubscriptionfile -subscriptionObject $subs -path $Path -extension $extension} | |
} | |
function Get-ReportSubscriptions | |
{ | |
param([object]$ssrsproxy, [string]$path) | |
$subscription = $ssrsproxy.ListSubscriptions($path) | |
$subscription | |
} | |
function New-DeserializedSSRSObject | |
{ | |
param($path, $filter = '*.xml') | |
$reportFiles = Get-ChildItem $path -Filter $filter | |
$reports = @() | |
foreach ($file in $reportFiles) | |
{ | |
try | |
{ | |
$reportobject = Import-Clixml -path ($file.fullname) -ErrorAction Ignore | |
} | |
catch | |
{ | |
Write-Verbose 'using error action ignore to ensure we only get files that are acctually cli xml files.' | |
write-verbose 'swallowing error' | |
$reportobject = $Null | |
} | |
If ($reportobject.subscription) | |
{ | |
Write-Verbose "Create a object of type ExtensionSettings" | |
$extensionSettings = New-Object -typename 'SSRSProxy.ExtensionSettings' | |
$extensionSettings.Extension = $reportobject.extensionSettings.Extension | |
$paramvalues = @() | |
foreach ($parameterField in $reportobject.extensionSettings.ParameterValues) | |
{ | |
if ($parameterfield.psobject.Properties.name[0] -eq 'ParameterName') #rebuild the object into an extenstion setting this one contains a parameter field reference | |
{ | |
$a = [SSRSProxy.ParameterFieldReference]::new() | |
Write-Verbose 'Create a object of type ParameterField reference.' | |
$a.FieldAlias = $parameterfield.fieldalias | |
$a.ParameterName = $parameterfield.ParameterName | |
} | |
elseif ($parameterfield.psobject.Properties.name[0] -eq 'Name') #rebuild the object into an extension settings object this one contains a param value | |
{ | |
$a = [SSRSProxy.ParameterValue]::New() | |
Write-Verbose 'Create a object of type ParameterValue reference.' | |
$a.Label = $parameterField.Label | |
$a.Name = $parameterField.Name | |
$a.Value = $parameterField.Value | |
} | |
$paramvalues += $a | |
} | |
$extensionSettings.ParameterValues = [ssrsproxy.parametervalueorfieldreference[]]$paramvalues | |
[SSRSProxy.DataRetrievalPlan]$DataRetrievalPlan = New-Object SSRSProxy.DataRetrievalPlan | |
Write-Verbose 'Create a object of type DataRetrievalPlan reference.' | |
#[SSRSProxy.DataSourceReference]$item = $reportobject.DataRetrievalPlan.Item | |
$DataRetrievalPlan.DataSet = $reportobject.DataRetrievalPlan.DataSet | |
[SSRSProxy.DataSourceReference]$dsReference = $reportobject.DataRetrievalPlan.Item | |
Write-Verbose "Datasource Reference $dsreference use the value for the datasource you want this data driven report to consume" | |
$DataRetrievalPlan.Item = $dsReference | |
$description = $reportobject.Description | |
$eventtype = $reportobject.eventtype | |
$matchdata = $reportobject.matchdata | |
#$b = [Ssrsproxy.parameterfieldreference]::new() | |
$paramvalues = @() | |
foreach ($parameterField in $reportobject.parameters) | |
{ | |
if ($parameterfield.psobject.Properties.name[0] -eq 'ParameterName') #rebuild the object into an extenstion setting this one contains a parameter field reference | |
{ | |
$a = [SSRSProxy.ParameterFieldReference]::new() | |
Write-Verbose 'Create a object of type ParameterField reference.' | |
$a.FieldAlias = $parameterfield.fieldalias | |
$a.ParameterName = $parameterfield.ParameterName | |
} | |
elseif ($parameterfield.psobject.Properties.name[0] -eq 'Name') #rebuild the object into an extension settings object this one contains a param value | |
{ | |
$a = [SSRSProxy.ParameterValue]::New() | |
Write-Verbose 'Create a object of type ParameterValue reference.' | |
$a.Label = $parameterField.Label | |
$a.Name = $parameterField.Name | |
$a.Value = $parameterField.Value | |
} | |
$paramvalues += $a | |
} | |
Write-Verbose 'Create a object of type parameterfieldreference reference.' | |
#$b.FieldAlias = $reportobject.parameters.fieldalias | |
#$b.ParameterName = $reportobject.parameters.ParameterName | |
$ParameterValueOrFieldReference = [Ssrsproxy.parameterfieldreference[]]$paramvalues | |
$itemPath = "$($reportobject.subscription.report)" | |
$reports += [PSCustomObject]@{ | |
'itemPath' = $itempath | |
'extensionSettings' = $extensionsettings | |
'DataRetrievalPlan' = $DataRetrievalPlan | |
'description' = $description | |
'eventtype' = $eventtype | |
'matchdata' = $matchdata | |
'ParameterValueOrFieldReference' = $ParameterValueOrFieldReference | |
} | |
} | |
} | |
$reports | |
} | |
function New-DataDrivenSubscription | |
{ | |
param([object]$ssrsproxy, | |
[Object]$reportObject, | |
[string]$destination = '/Reports' | |
) | |
$src = $dest = $null | |
Write-Verbose "function asssumes that a report object has been created to push to the destination" | |
$src = ([uri]$reportobject.DataRetrievalPlan.Item.reference).absoluteuri | |
$dest = (([uri]$destination).absoluteuri) | |
if ($dest) | |
{ | |
if ($dest.EndsWith('/')) | |
{ | |
$dest.trimend('/') | |
} | |
} | |
[SSRSProxy.DataSourceReference]$dsReference = $reportobject.DataRetrievalPlan.Item | |
if ($src -and $dest) #since .aboluteuri is only present with an actual uri this will let us know this is an actual uri. | |
{ | |
write-verbose "source and destination are sharepoint" | |
$datasourceName = $src -split '/' | Select-Object -last 1 | |
$src = $src -replace "/$datasourceName", '' | |
$dsReference.Reference = ((([uri]$reportobject.DataRetrievalPlan.Item.Reference).AbsoluteUri) -replace $src, $dest) | |
$reportObject.itempath = ("$destination/$($reportobject.itempath)") | |
$dsReference.Reference | |
} | |
elseif ($src -and (-not $dest)) | |
{ | |
write-verbose "source is sharepoint destintation is native" | |
$datasourceName = $src -split '/' | Select-Object -last 1 | |
$dest = $destination | |
$src = $src -replace "/$datasourceName", '' | |
$dsReference.Reference = ((([uri]$reportobject.DataRetrievalPlan.Item.reference).AbsoluteUri) -replace $src, $dest).Trim('.rsds') | |
$reportObject.itemPath = ("$destination/$($reportobject.itempath)").trim('.rdl') | |
$dsReference.Reference | |
} | |
elseif ($dest -and (-not $src)) | |
{ | |
write-verbose "destination is sharepoint and source is native" | |
$src = $reportobject.DataRetrievalPlan.Item.reference | |
$datasourceName = $src -split '/' | Select-Object -last 1 | |
$src = $src -replace "/$datasourceName", '' | |
$dsReference.Reference = ($src -replace $src, "$dest/$datasourceName") | |
$reportObject.itemPath = ("$destination/$($reportobject.itempath)") | |
$dsReference.Reference | |
} | |
else | |
{ | |
write-verbose "destination and source are native" | |
$dest = $destination.trimend('/') | |
$src = $reportobject.DataRetrievalPlan.Item.reference | |
$datasourceName = $src -split '/' | Select-Object -last 1 | |
$src = $src.trimend("/$datasourceName") | |
$dsReference.Reference = (($reportobject.DataRetrievalPlan.Item.reference).trimend("/$datasourcename") -replace $src, "$dest/$datasourcename").trim('.rsds') | |
$reportObject.itemPath = ("$destination/$($reportobject.itempath)").trim('rdl') | |
$dsReference.Reference | |
} | |
$reportObject.DataRetrievalPlan.Item = $dsReference | |
try | |
{ | |
Write-Verbose "Now that the object is re-constituted we can put this in the SSRS instance we wish to push it to" | |
if (($reportObject.ParameterValueOrFieldReference.fieldalias) -and ($reportObject.ParameterValueOrFieldReference.ParameterName)) | |
{ | |
$ParameterValueOrFieldReference = $reportObject.ParameterValueOrFieldReference | |
} | |
else { $ParameterValueOrFieldReference = $Null} | |
$status = $ssrsproxy.CreateDataDrivenSubscription($reportObject.itempath , $reportObject.extensionsettings , $reportObject.DataRetrievalPlan, $reportObject.description, $reportObject.eventtype, $reportObject.matchdata, $ParameterValueOrFieldReference) | |
} | |
Catch | |
{ | |
$line = $_.InvocationInfo.ScriptLineNumber | |
$err = "Error was $_ `nError was in Line $line" | |
$err = $err + $error[0] | |
$err += "($reportObject.itempath , $reportObject.extensionsettings , $reportObject.DataRetrievalPlan, $reportObject.description, $reportObject.eventtype, $reportObject.matchdata, $ParameterValueOrFieldReference)" | |
Throw "Something is wrong check errors $err" | |
} | |
$status | |
#> | |
} | |
function Remove-DatadrivenSubscription | |
{ | |
param([object]$ssrsproxy, | |
[string]$SubscriptionId) | |
try | |
{ | |
$ssrsproxy.DeleteSubscription($SubscriptionId) | |
} | |
catch | |
{ | |
"Error was $_" | |
$line = $_.InvocationInfo.ScriptLineNumber | |
"Error was in Line $line" | |
} | |
} | |
<#class SSRSObject | |
{ | |
[SSRSProxy.Subscription[]]$subscription | |
[string]$Owner | |
[SSRSProxy.ExtensionSettings]$ExtensionSettings | |
[SSRSProxy.DataRetrievalPlan]$DataRetrievalPlan | |
[string]$Description | |
[SSRSProxy.ActiveState]$Active | |
[string]$Status | |
[string]$EventType | |
[string]$MatchData | |
[object]$Schedule | |
[SSRSProxy.ParameterValueOrFieldReference[]]$Parameters | |
}#> | |
function Invoke-SSRSobject | |
{ | |
$ssrsobject = @' | |
class SSRSObject | |
{ | |
[SSRSProxy.Subscription[]]$subscription | |
[string]$Owner | |
[SSRSProxy.ExtensionSettings]$ExtensionSettings | |
[SSRSProxy.DataRetrievalPlan]$DataRetrievalPlan | |
[string]$Description | |
[SSRSProxy.ActiveState]$Active | |
[string]$Status | |
[string]$EventType | |
[string]$MatchData | |
[SSRSProxy.ParameterValueOrFieldReference[]]$Parameters | |
} | |
'@ | |
Invoke-Expression $ssrsobject | |
#. $ExecutionContext.InvokeCommand.NewScriptBlock($ssrsobject) | |
} | |
function Get-CustomPowerShellClasses | |
{ | |
[appdomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.GetCustomAttributes($false) | Where-Object { $_ -is [System.Management.Automation.DynamicClassImplementationAssemblyAttribute]} } | ForEach-Object { $_.GetTypes() | Where-Object IsPublic } | |
} |
updated the new-DeserializedSSRSObject to allow for nested items in parameters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The other module for this scripting is found here:
https://gist.github.com/crshnbrn66/b10e43ef0dadf7f4eeae620428b2cdd9