ESP Workload Automation

 View Only
  • 1.  Arguments with PowerShell Script

    Posted Aug 16, 2018 10:31 PM

    Hello, 

     

    I am hoping someone can help. I am in the process of converting our companies BATCH scripts to PowerShell. I use the COMMAND to call PowerShell & then the ARGS to pass the script path and arguments. The Simulation passed ESP, but the agent failed. 

     

    I guess my question would be, is it possible to use commas in the arguments? The script is in charge of restarting service on a couple of servers, and I setup an array in my PowerShell script to reduce the amount of lines in the code. 

    Here is what the spool file shows:

    Output of messages for workload object QSVRTEST/SVRQNT.1/MAIN
    Start date Thu Aug 16 22:21:34 2018
    ----------------------------------------------------------------
    D:\SCRIPTS\SERVICERESTART\SERVICERESTART.PS1 : A parameter cannot be found that matches parameter name 'SVRSNAME
    SERVER1,SERVER2 -SERVICENAME SPOOLER'.
    + CategoryInfo : InvalidArgument: (:) [SERVICERESTART.PS1], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : NamedParameterNotFound,SERVICERESTART.PS1

     

    Here is what I have setup:

     

    NT_JOB QSVRTEST +
    LONGNAME(QSVR_RESTART_SERVICE_SPOOLER)
    AGENT AGNT1
    CMDNAME C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0\POWERSHELL.EXE
    ARGS -FILE "D:\SCRIPTS\SERVICERESTART\SERVICERESTART.PS1" +
    "-SVRSNAME SERVER1,SERVER2 -SERVICENAME SPOOLER"
    RUN ANY
    RESOURCE ADD(1,SVR_AGNT1_REN)
    ENDJOB

     

    Anyone help would be appreciated! 

     

    Thank you,

    Mike



  • 2.  Re: Arguments with PowerShell Script

    Posted Aug 17, 2018 07:41 AM


  • 3.  Re: Arguments with PowerShell Script

    Posted Aug 17, 2018 10:29 AM

    I can't even spell ESP but you may need to break up your arguments, for example:

     

    ARGS "-FILE" "D:\SCRIPTS\SERVICERESTART\SERVICERESTART.PS1" +
    "-SVRSNAME SERVER1,SERVER2" "-SERVICENAME SPOOLER"

     

    or something along those lines. The error is implying that it cannot match args to your scripts param block.



  • 4.  Re: Arguments with PowerShell Script

    Posted Aug 17, 2018 12:23 PM

    Along Mark's line of thinking, since there are no spaces in any of the ARGS you probably eliminate all quotes.

     

    ARGS -FILE D:\SCRIPTS\SERVICERESTART\SERVICERESTART.PS1 + 
    -SVRSNAME SERVER1,SERVER2 -SERVICENAME SPOOLER

     

    How many parameters does the PS1 script expect?

     

    If you open a command prompt in Windows how would you code the command line?



  • 5.  Re: Arguments with PowerShell Script
    Best Answer

    Broadcom Employee
    Posted Aug 18, 2018 12:27 AM

    Hi,

    Like Rick and Mark pointed out, the script may not be expecting the commas.  I created a very simple PS script and passed arguments with comma.  

    param(

      [string]$args

    )

    Write-Host "[$args]"

    The script when ran manually took comma separated args.  While testing on the CA WA Agent ran it exactly as I tested it on PowerShell prompt.

    In PowerShell

    PS C:\Users\Administrator\Desktop> .\input.ps1 -args one,two,three,four
    [one two three four]

    From the CA WA Agent spool output:

    Output of messages for workload object HELLO_PS1/POWERSHELL.4/MAIN

    Start date Fri Aug 17 21:23:18 2018

    ----------------------------------------------------------------

    [one two three four]

     

    Thank you,

     

    Nitin Pande

    CA Technologies



  • 6.  Re: Arguments with PowerShell Script

    Broadcom Employee
    Posted Aug 27, 2018 08:31 AM

    Hi Mike,

     

    Have you got the chance to review the replies from Rick, Mark and Nitin?

     

    Are they helpful?

     

    Do you have any more questions?

     

    Thank you for your feedback!

     

    Lucy