I have a script that I’m trying to give parameters to so that you can call it from PowerShell and pass parameters, but it doesn’t work unless I paste it into the ISE and hit ‘Run Script’, then the parameters are asked for in the Console pane and it works. But if I call the script from the Console like this:
./Update-SSRSSubscriptionPasswords -SSRSWebServiceURL http://servername/ReportServer-UserName user.name-Password "P@$$word01"
I get an exception about the arguments being passed in line 142. (The setSubscriptProperties call)
Iv’e tried turning this into a function and .sourcing it and calling the function, I get the same error. It literally only works if I “Run Script” from the ISE.
Here is my script. Any assistance with what I’m doing wrong would be great!!
# function Update-SSRSSubscriptionPasswords { #[cmdletBinding()] param ( [Parameter(Mandatory=$true,Position=1)] [string]$SSRSWebServiceURL, [Parameter(Mandatory=$true,Position=2)] [string]$UserName, [Parameter(Mandatory=$true,Position=3)] [string]$Password ) # update this value with the Web Service URL value from the Reporting Service Configuration Manager # $WebServiceURL = "http://servername/ReportServer" # $username = USER.NAME # $password = INFO" $WebServiceURL = $SSRSWebServiceURL $username = $UserName $password = $Password #Write-Host "Applying Update to: $SSRSWebServiceURL" #Write-Host "Username: $UserName" Write-Host "Password: $password" # If no password is passed, then you will receive information on what Datasource and/or Subscriptions are assigned to the User given $InformationOnly = $true if (!$password.Equals("info")) { $InformationOnly = $false } Write-Host "Information Only: $($InformationOnly)" $uri = "$($WebServiceURL)/ReportService2010.asmx?WSDL" $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 = "" $MatchData = $null $PasswordUpdated = $false $ExtensionPassword = New-Object ($ParmValueDataType) $ExtensionPassword.Name = "PASSWORD" $ExtensionPassword.value = $password $reports = $reporting.listchildren("/", $true) | Where-Object {$_.TypeName -eq "Report"} foreach ($Report in $Reports) { $Subscriptions = $ssrs.ListSubscriptions($report.Path) foreach ($Subscription in $Subscriptions) { $ReportSubscriptionID = [String]$subscription.SubscriptionID foreach ($ParmValueObj in $Subscription.DeliverySettings.ParameterValues) { 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) $SubscriptionProperties Write-Host "MatchData: $($matchdata.Value)" $iExtParamCnt = $ExtensionSettingsObj.ParameterValues.Length $i = 0 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..." } $i++ if ($i -eq $iExtParamCnt) { Write-Host "Adding Parameter..." $ExtensionSettingsObj.ParameterValues += $ExtensionPassword $PasswordUpdated = $true } } if ($PasswordUpdated) { if (!$InformationOnly) { $SubscriptionProperties = $ssrs.SetSubscriptionProperties($ReportSubscriptionID, $ExtensionSettingsObj, $description.Value, $eventType.Value, $matchdata.Value, $ParmValueObj) Write-Host "Password Updated..." } } } } } } } } # }