Created
November 25, 2014 19:04
-
-
Save kitmenke/7049b91819537bac4bc3 to your computer and use it in GitHub Desktop.
Powershell script to change the owner of a subscription to another user
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
Write-Host '*************************************' | |
Write-Host 'Change Subscription Owner starting...' | |
Write-Host '*************************************' | |
$oldOwner = "domain\user1" | |
Write-Host "Old Owner = $oldOwner" | |
$newOwner = "domain\user2" | |
Write-Host "New Owner = $newOwner" | |
$itemPathOrSiteURL = "http://servername/sites/subsite" | |
Write-Host "Item Path or Site URL = $itemPathOrSiteURL" | |
$reportServerUri = "http://servername/_vti_bin/ReportServer/ReportService2010.asmx?wsdl" | |
Write-Host "Report Server URI = $reportServerUri" | |
$proxy = New-WebServiceProxy -Uri $reportServerUri -UseDefaultCredential; | |
$proxy.Timeout = 120000 | |
Write-Host "Listing subscriptions for $itemPathOrSiteURL..." | |
$subscriptions = $proxy.ListSubscriptions($itemPathOrSiteURL) | |
$num = $subscriptions.length | |
Write-Host "Found $num subscriptions!" | |
$num = 0 | |
Write-Host "Looking for subscriptions where owner = $oldOwner..." | |
foreach ($subscription in $subscriptions) { | |
if ($subscription.Owner -eq $oldOwner) { | |
$subscriptionId = $subscription.SubscriptionID | |
Write-Host " ChangeSubscriptionOwner($subscriptionId, $newOwner)" | |
Try { | |
$proxy.ChangeSubscriptionOwner($subscriptionId, $newOwner) | |
$num += 1 | |
} Catch { | |
Write-Host "Error changing owner: $_" | |
} | |
} | |
} | |
Write-Host "Successfully changed $num subscription owners!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment