Skip to content

Commit 4e78daa

Browse files
committed
Added block to handle setting the Owner of the subscription to the Owner being piped in.
1 parent 8972713 commit 4e78daa

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

ReportingServicesTools/Functions/CatalogItems/Copy-RsSubscription.ps1

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function Copy-RsSubscription
3434
Use "New-RsWebServiceProxy" to generate a proxy object for reuse.
3535
Useful when repeatedly having to connect to multiple different Report Server.
3636
37+
.PARAMETER SkipOwner
38+
Used to skip attempting to change the owner of a subscription to the owner being piped in.
39+
3740
.EXAMPLE
3841
Get-RsSubscription -ReportServerUri 'http://localhost/ReportServer_sql14' -RsItem '/path/to/my/oldReport' | Copy-RsSubscription -ReportServerUri 'http://remote-machine:8080/reportserver_sql16' -RsItem '/path/to/newReport'
3942
@@ -58,6 +61,18 @@ function Copy-RsSubscription
5861
-----------
5962
This command will establish a connection to the Report Server located at http://localhost/ReportServer_sql14 using current user's credentials get all the paths from all reports at '/Origin' folder.
6063
Then it uses the $paths variable to get all existing subscriptions and pipe the results to Copy-RsSubscription which will create a new subscription on each report that exists with the same name on the destination folder '/New Folder' located at Report Server 'http://remote-machine:8080/reportserver_sql16'
64+
65+
.EXAMPLE
66+
Import-RsSubscriptionXml .\MySubscriptions.xml | Copy-RsSubscription -RsItem /Example/Report -SkipOwner $True
67+
68+
Description
69+
-----------
70+
This command will import all the subscriptions contained in .\MySubscriptions.xml, recreate any SRSS specific properties
71+
and pipe the results to Copy-RsSubscription which will add them to the /Example/Report report. The newly copied
72+
subscriptions will have their owner set to the person running the command since the -SkipOwner parameter was supplied
73+
with a value of $True.
74+
NOTE: You will need to supply the correct path for the -ReportServerUri parameter to both the Import-RsSubscriptionXml
75+
& Copy-RsSubscription functions. It has been omitted from this example for brevity.
6176
#>
6277

6378
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
@@ -83,7 +98,11 @@ function Copy-RsSubscription
8398

8499
[Parameter(Mandatory = $True, ValueFromPipeline=$true)]
85100
[object[]]
86-
$Subscription
101+
$Subscription,
102+
103+
[parameter(Mandatory = $False)]
104+
[System.Boolean]
105+
$SkipOwner = $False
87106
)
88107
Begin
89108
{
@@ -142,6 +161,15 @@ function Copy-RsSubscription
142161
OriginalReport = $sub.Path
143162
}
144163
Write-Verbose "Subscription created successfully! Generated subscriptionId: $subscriptionId"
164+
if ($SkipOwner -eq $False)
165+
{
166+
try {
167+
$proxy.ChangeSubscriptionOwner($subscriptionId,$sub.owner)
168+
}
169+
catch {
170+
Write-Warning "Unable to change owner of $($subscriptionId) after creating subscription because: $($_.Exception.Message)"
171+
}
172+
}
145173
}
146174
}
147175
}

0 commit comments

Comments
 (0)