Kaseya Community

Create Global Variable in Sub Procedure - Please Help!

This question is not answered

Is this possible and has anyone done it?
I just want to be able to pass variables to agent procedures..   Thank You !!!!!

All Replies
  • Can you tell us more ?

    What do you want to do? You could use the global:variables or the <managedvariable> to pass arguments to other procedure, or simply write a file and if the file exists do a statement or other statements...

  • Two commonly ways to pass variables from a sub procedure;

    1) Use the Universal Variable

    2) Write the value to a text file with the sub procedure and read it into a variable in your main procedure

    The first option limits you to 3 variables at a time (Steps > System > getVariableUniversal...)

    The second option allows you to create unlimited variables but requires a bit more work.

  • I never thought of the text file..

    As far as the universal variable - I will have to try that also, i think I was trying to create them wrong..

    Thank you!

  • That would work going from a Agent Procedure into a service desk - I am actually trying to do this backwards..  I want to create the variable in a service desk sub procedure..  No option ( that i can tell ) to create a universal or a text file ( outside echoing a shell command )...  

  • In short - I am looking to pull a variable form a ticket in service desk and use it in a script..  

  • This should work although the “WriteFileFromAgent” step is a bit flaky

    1) IN SD  you can schedule a script to run on a specific machine

    a. Use "GetAgentIno" step to create an SD Variable that is the Agentguid for the machine the ticket relates to

    b. Use ExecuteShellCommand to write a text file with a SPECIFC NAME into the Agent folder on the Kaseya Server

    i. E.g. C:\Kaseya\UserProfiles\177052717621270\GetFiles  or  C:\Kaseya\UserProfiles\177052717621270\docs

    ii. Use the format for the path as C:\Kaseya\UserProfiles\[=AgentGuid=]\GetFiles\FILENAME.TXT

    iii. Include in the FILENAME.TXT the information you want to pass to your agent procedure

    2) Now you can do 1 of 2 things here

    a. In SD you could ScheduleAgentProcedure and have SD call your script on the machine the ticket relates to

    b. OR just use Agent procedure Schedule to run the script.

    Either way you want the Agent procedure to read the content of the file you created

    So within the actual Agent procedures there is a step called “WriteFileFromAgent”

    Step 1 in your agent procedure is to copy the file from the Kaseya Server folder C:\Kaseya\UserProfiles\[=AgentGuid=]\GetFiles\FILENAME.TXT  to your localmachines Kworking folder

    Then as FILENAME.TXT is now local the script can read the content of the file and use it as a variable within your Agent Procedure

    Should work .. haven't tested but in theory all the pieces are there.

    Cheers

    Paul

  • Well - ok then..  I will have to try this and let you know..  Thank you!

  • In SD executeCommandShell is different from agent procedure. how do i put "approved command shells? and will the command line "C:\Kaseya\UserProfiles\[=AgentGuid=]\GetFiles\FILENAME.TXT" recognize the variable [=AgentGuid=] or will it make a folder literally named [=AgentGuid=]?