Kaseya Community

Powershell commands in Agent Procedures

  • Hi,

    Is it possible to use Powershell commands in agent procedures that are not listed in the Available Statements pane in the Agent Procedure Editor?

    I would like to write Powershell scripts with commands that aren't available in the editor.  

    Thank you

  • ,

    Depending on what you're trying to do, one option is to create your PS script in a batch file, then use Kaseya to execute the batch file.  

  • Ok, got it.  That makes sense.  Only problem is that the execution policy is set to restricted on all of our endpoints.  I suppose I can run a batch file to set it to unrestricted, then run a batch file to run the powershell script.  Would that work?

    Thank you

  • When you execute powershell.exe from your batch file, just use "-ExecutionPolicy Bypass" too.

    technet.microsoft.com/.../hh847736.aspx

  • That's perfect!  Thank you very much.

  • Hello GeorgeC,

    You can run anything you want with the ExecutePowershell commands.

    As mentioned above, by running a ps1 command or by quick one liners that can do a lot.

    This for example uses COM to find the Itunes Version and uses a Try Catch in case there's no Ole interface available.

    All without uploading scripts...


  • I see.  This is great!  So I can actually run individual PowerShell commands with this, or run a PS1 file without worrying about the execution policy set on the machine.  Fantastic!

    Regarding the ExecutePowershellCommand64BitSystem() or User() commands, what is the difference between the two?  Does it have to do with the account permissions the command is run with?

    Thank you

  • From the user Manual:

    System and user commands:

    System - If a system command is run, execution is restricted to the agent's system level access.

    User - If a user command is selected, then a credential must be specified by running either the impersonateUser() or useCredential() command before this command.

    Generally you use System to run a Script with more elevated privilege on the machine and to ensure the script works even if there's no user logged on.

    You use by User mostly when you want to run it as Current Logged user (unless you specify ImpersonateUser / UseCredential.

    Also make sure you have Administrative Credential Stored in the Agent by going to:

    Agent -> Configure Agent -> Set Credential.

  • Got it.  Thank you Alessandro.  This is very helpful.