Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update subscription password with powershell

Status
Not open for further replies.

Kawika Moss

Programmer
Aug 31, 2017
2
0
0
US
When you have to update your AD credentials, you then have to go in and update your password for all the datasources and subscriptions, in SSRS, that are owned by you.

I'm trying to automate this with a PS script. What I have so far is...

Code:
$uri = "[URL unfurl="true"]http://localhost//ReportServer_KESSEL/ReportService2010.asmx?WSDL"[/URL]
$password = 'newPassword'
$username = 'kawika.moss'
$UpdatePassword = $true


$reporting = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "ReportingService2010" -class Reporting
$reporting.url = $uri	#Makes sure URL is set correctly after call; sometimes this flips to a default URL

$details = new-object -TypeName System.String -argumentList ("")


##Initialize Variable Types required for GetSubscription call
$ExtensionSettings = new-object -TypeName ReportingService2010.ExtensionSettings
$ExtensionRow = new-object -TypeName ReportingService2010.ExtensionSettings
$Description = new-object -TypeName System.String -argumentList ("")
$Active =  new-object -TypeName ReportingService2010.ActiveState
$Status = new-object -TypeName System.String -argumentList ("")
$EventType = new-object -TypeName System.String -argumentList ("")
$MatchData = new-object -TypeName System.String -argumentList ("")
$Parameters = new-object -TypeName ReportingService2010.ParameterValue

# $ExtensionSettings = ''
# $ExtensionRow = ''
# $Description = ''
# $Active = ''
# $Status = ''
# $EventType = ''
# $MatchData = ''
# $Parameters = ''

$DataRetrievalPlan = new-object -TypeName ReportingService2010.DataRetrievalPlan
$ParametersValue = new-object -TypeName ReportingService2010.ParameterValue
$subscriptions= new-object -TypeName ReportingService2010.Subscription
$subscription= new-object -TypeName ReportingService2010.Subscription
$ExtensionPassword = new-object -TypeName ReportingService2010.ParameterValue
		
$reports = $reporting.listchildren("/", $true) | Where-Object {$_.TypeName -eq "Report"}
# $reports

$ExtensionPassword.Name = "PASSWORD"
$ExtensionPassword.value = $password

#Write-host $dataSource.Item.UserName


#$subscriptions += $rs2010.ListSubscriptions("/"); # use "/" for default native mode site 


foreach ($report in $reports){

    $subscriptions = $reporting.ListSubscriptions($report.Path)
    #$subscriptions

	foreach ($subscription in $subscriptions){
	    $ReportSubscriptionID = [String]$subscription.SubscriptionID	#Sets a variable to the SubscriptionID Value
        #$ReportSubscriptionID
        If ($ReportSubscriptionID){
		    ##Looks through the extensions stored within the subscription for Username/Password
		    foreach ($ParameterValue in $subscription.DeliverySettings.ParameterValues){
			    If ($ParameterValue.name -eq "USERNAME"){	#Finds the username parameter 
                        write-host $ParametersValue.Value                   
				    If ($ParameterValue.value -eq $username){	#Checks if this is the username we are looking for
					    Write-Host " Subscription Name: " $subscription.Report
					    #Write-Host "   SubscriptionID: " $Subscription.SubscriptionID
					    Write-Host "   DeliveryExtension: " $subscription.DeliverySettings.Extension
					    write-host "      Field: " $ParameterValue.name
					    #write-host "      Label: " $ParameterValue.label		##Not used
					    write-host "       Value: " $ParameterValue.value

                        #Sets the new password
					    $PasswordUpdated = $false
					    If ($UpdatePassword -eq $true){
						    $details = ""
						    #Gets the subscription Properties prior to updating the password
						    $details = $reporting.GetSubscriptionProperties($Subscription.SubscriptionID, [REF]$ExtensionSettings, [REF]$Description, [REF]$Active, [REF]$Status, [REF]$EventType, [REF]$MatchData, [REF]$ParametersValue)
								
						    $i=0	#initialize counter variable
						    foreach ($ExtensionRow in $ExtensionSettings.ParameterValues){		#Pulls all the ExtensionSettings
							    write-host "       ExtensionRow: " $ExtensionRow.name
							    write-host "       ExtensionRow.Values: " $ExtensionRow.value
							    If ($ExtensionRow.name -eq "PASSWORD"){	#Checks to see if PASSWORD is unencrypted and available to pull
                                    Write-Host "updating password..."
							     #$ExtensionRow.value = $password	#Sets the value
							     Write-Host "!!   WARNING: Unencrypted password retrieved" -ForegroundColor "Red"
							     $PasswordUpdated = $true
							     break	#Exits for loop -- password updated, now to commit change
							   }
							    $i++	#Increments counter
							    If ($ExtensionSettings.ParameterValues.count -eq $i){	#Determines if this is the final iteration and whether the password field was found
								    $ExtensionSettings.ParameterValues += $ExtensionPassword
								    $PasswordUpdated = $true
								    break	#Exits for loop -- member group added and set
								    #}
							    }
						    }
                        
						     # #Sets the Subscription settings -- with the new Password
						     # If ($PasswordUpdated -eq $true){	#Password has actually been updated
							 #     $details = $reporting.SetSubscriptionProperties($ReportSubscriptionID, $ExtensionSettings, $Description, $EventType, $MatchData, $ParametersValue)
						     # }
						     # ELSE{
							 #     Write-Host "     ERROR: PASSWORD NOT UPDATED" -ForegroundColor "Red"
						     # }
					    }					    
				    }
			    }
		    }
	    }	    
    }
}

And the error I'm getting is:

Error said:
Exception calling "GetSubscriptionProperties" with "8" argument(s): "Cannot convert the "System.Management.Automation.PSReference`1[ReportingService2010.ExtensionSettings]" value of type
"System.Management.Automation.PSReference`1[[ReportingService2010.ExtensionSettings, dnxukfbc, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]" to type
"ReportingService2010.ExtensionSettings"."
At C:\Users\kawika.moss\Documents\PowershellScripting\TestUpdateSubscriptionPassword.ps1:76 char:11
+ $details = $reporting.GetSubscriptionProperties($Subscription.Subscrip ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: :)) [], MethodInvocationException
+ FullyQualifiedErrorId : PSInvalidCastException

I got most of this script from a script that was already out there, located at Manage Subscriptions

Does anyone have an idea of how to do this, this would save hours of time...btw, we are using 2008R2.

Thanks!
 
ok, so I figured out how to use the getSubscriptProperties method, with PowerShell, but I hit another snag. There is no ExtensionSettingwsObj row for Password. So how do I set the password, if there is not setting for password?

here is my current code, that get's the info I need. I was expecting to get the setting for Password, update it with a new password and then use the setSubscriptionProperties to get it set...

Code:
$uri = "[URL unfurl="true"]http://localhost//ReportServer/ReportService2010.asmx?WSDL"[/URL]
$username = 'username'

$ReportServerUriSource = $uri;
$global:ssrs = New-WebServiceProxy -Uri $ReportServerUriSource -UseDefaultCredential;
$type = $ssrs.GetType().Namespace

#Define Object Types for Subscription property call
$ExtensionSettingsDataType = ($type + '.ExtensionSettings')
$ActiveStateDataType = ($type + '.ActiveState')
$ParmValueDataType = ($type + '.ParameterValue')

$ExtensionSettingsObj = New-Object ($ExtensionSettingsDataType)
$ActiveStateObj = New-Object ($ActiveStateDataType)
$ParmValueObj = New-Object ($ParmValueDataType)
$Description = $null
$Status = $null
$EventType = $null
$MatchData = $null
 
$reports = $reporting.listchildren("/", $true) | Where-Object {$_.TypeName -eq "Report"}

foreach ($Report in $Reports) {

    $Subscriptions = $ssrs.ListSubscriptions($report.Path)

    foreach ($Subscription in $Subscriptions) {
        
        foreach ($ParmValueObj in $Subscription.DeliverySettings.ParameterValues) {
            #Write-Host "Subscription Parameter - NAME: $($ParmValueObj.name) Subscription Parameter - VALUE: $($ParmValueObj.Value)"
            if ($ParmValueObj.name -eq "USERNAME") {

                # Write-Host "UserName: $($ParmValueObj.Value)"

                if ($ParmValueObj.Value -eq $username) {
                    
                    Write-Host ""
                    Write-Host "Subscription Name: " $subscription.Report
					Write-Host "SubscriptionID: " $Subscription.SubscriptionID
					Write-Host "DeliveryExtension: " $subscription.DeliverySettings.Extension
					write-host "Field: " $ParmValueObj.name					
					write-host "Value: " $ParmValueObj.value

                    if ($Subscription.IsDataDriven.ToString() -eq "False") {
        
                        #GET SUBSCRIPTION PROPERTIES
                        $SubscriptionProperties = $SSRS.GetSubscriptionProperties($Subscription.SubscriptionID.ToString(),` [ref]$ExtensionSettingsObj, ` [ref]$description, ` [ref]$ActiveStateObj, ` [ref]$status, ` [ref]$eventType, ` [ref]$matchdata, ` [ref]$ParmValueObj)            
        
                        foreach ($ExtensionRow in $ExtensionSettingsObj.ParameterValues){		#Pulls all the ExtensionSettings

			                write-host "ExtensionRow - NAME: $($ExtensionRow.name) ExtensionRow - VALUE: $($ExtensionRow.value)"
                            
                
                            if ($ExtensionRow.name -eq "PASSWORD") {
                                Write-Host "Password Unencrypted..."
                            }			    
		                }                      
                    }
                }
            }
        }        
    }
}

Does this mean that the password is encrypted and I can't get that setting and in turn, I can't update it?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top