Kaseya Community

how do you handle powershell scripts that have multiple lines?

  • There are different ways to use powershell scripts in agent procedures.
    Either I write the script as usual and upload the script via managed files to the VSA server and then use it:

    if you don't want to load everything as scripts on the VSA server you can have the script generated dynamically during runtime.
    executeShellCommand("echo powershell code first line">>#vAgentConfiguration.agentTempDir#\powershell_script.ps1")
    executeShellCommand("echo powershell code second line">>>>#vAgentConfiguration.agentTempDir#\powershell_script.ps1")
    executeShellCommand("echo powershell code third line">>>>#vAgentConfiguration.agentTempDir#\powershell_script.ps1")
    executeShellCommand("echo powershell code and so on">>>>#vAgentConfiguration.agentTempDir#\powershell_script.ps1")
    I'd be interested to know how you solve it.
    thx for ur answers

    format code in table
    [edited by: exitsys at 12:31 AM (GMT -7) on Jun 4, 2020]
  • using writefile to upload scripts to endpoints is pretty much the only thing that works consistently for me.

  • If the script isn't too long you can use a semicolon to have multiple lines into one line.

  • We also use "echo" to build ps1 powershell scripts on the fly. It's especially useful when using #vars#. Seems to work pretty well. no complaints.

    Another method  is using the pipe | in the command line.