IT Process Automation

 View Only
  • 1.  How to pass an array to a PowerShell script?

    Posted Oct 01, 2018 03:47 AM

    Hi Team,


    Is there any way to pass an array to a PowerShell script?

    Able to pass a variable except array.But when trying to pass an array using same method getting an error "Cannot convert progam parameter at position 0 to string"




  • 2.  Re: How to pass an array to a PowerShell script?
    Best Answer

    Posted Oct 04, 2018 04:16 PM
      |   view attached

    Hi Pankaj,


    What I have been doing since upgrading to CAPA 4.3.2 is using the REST API to read the DataSet variables from the job and converting it into a PowerShell Object.

    This allows me to pass all kinds of complex variable types (except passwords) to PowerShell and not having to worry about fancy parsing.


    I have attached a sample version of the PowerShell code that I use, the only parameters you need to pass to the script are as follows:

    [string]$CAPA_Username        Username of account that has access to the process 
    [string]$CAPA_Password         Password of account that has access to the process  
    [string]$CAPA_ServerName    Base URL of the CAPA Server (i.e. capa-automation-dev.***.***:8443)
    [string]$CAPA_InstanceID       Instance ID of the job that you want to retrieve the data for



    The script will convert the results of the REST API call to an object, when you want to retrieve a variable from the object you just call the function and pass the CAPA variable name.

    i.e. ReturnDataSetVariable "Environment.SCOM.Preproduction"

    In the case of an array (because the index is appended to the name), you can pass the name with a * at the end, and it will return a list of the values


    Key                                                          Value
    ---                                                             -----
    Environment.SCOM.Preproduction[0]    server-1.***.***
    Environment.SCOM.Preproduction[1]    server-2.***.***
    Environment.SCOM.Preproduction[2]    server-3.***.***


    Hope this helps!



  • 3.  RE: Re: How to pass an array to a PowerShell script?

    Posted Nov 19, 2019 09:12 AM
    Hi Ian,

    I could review and understand the script that you have attached to this thread, but not able to figure out where you have used the script.
    Can you explain where did you use the script, you are referring that you read the dataset values from a Job and converted them to Powershell Object, how you have created a job with the Powershell script?

    thank you.