Kaseya Community

Script variables and scope... (K2)

  • When creating variables within an if block and that if block ends (but my script continues), it looks like I loose the value being held by that variable.

    Even when I declare the variable before starting the if block, any assignment done within the block is not retained.

    Is this default behavior or a bug (or have I screwed up somewhere Smile?

    Legacy Forum Name: Script variables and scope... (K2),
    Legacy Posted By Username: Zestysoft
  • I have also noticed this and it seems to be ‘normal’. It seems like te variable in the IF block is actually another variable.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: ChristiaanO
  • You have to store variables in the file system / registry for now.

    For example, if I need to store a variable, I will just use an execute shell command of 'echo [insertvariablecontentshere] >> "#vagentconfiguration.agenttempdir#\[somefilename]"'

    I will then use an IF check using TEST FILE to look for that file and if I want to analyze it's contents.

    Make sense?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Benjamin.Lavalley@kaseya.com
  • Benjamin.Lavalley@kaseya.com
    You have to store variables in the file system / registry for now.

    For example, if I need to store a variable, I will just use an execute shell command of 'echo [insertvariablecontentshere] >> "#vagentconfiguration.agenttempdir#\[somefilename]"'

    I will then use an IF check using TEST FILE to look for that file and if I want to analyze it's contents.

    Make sense?


    Is there a safe way to store a variable value in such a way that the cli doesn't attempt to interpret it? I.E. say my variable contains the string "%hello%" or "this && that" or "a > b > c", etc...

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Zestysoft
  • Zestysoft
    Is there a safe way to store a variable value in such a way that the cli doesn't attempt to interpret it? I.E. say my variable contains the string "%hello%" or "this && that" or "a > b > c", etc...


    Sure, write a registry key. Actually that sounds like a better idea now that you mention possible command line complications. Thanks Smile

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Benjamin.Lavalley@kaseya.com