Script only works if I run from ISE

Welcome Forums General PowerShell Q&A Script only works if I run from ISE

This topic contains 1 reply, has 1 voice, and was last updated by

1 year, 8 months ago.

  • Author
  • #78946

    Topics: 21
    Replies: 51
    Points: 0
    Rank: Member

    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 "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 {
        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 ($ -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: " $					
    					    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)    
                                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 - VALUE: $($ExtensionRow.value)"                            
                                    if ($ -eq "PASSWORD") {
                                        Write-Host "Password Unencrypted..."
                                    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..."
    # }
  • #78949

    Topics: 21
    Replies: 51
    Points: 0
    Rank: Member

    Well, it was line 142 in my ISE, but on here it is line 113

The topic ‘Script only works if I run from ISE’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort