Kaseya Community

Reading each line to a separate variable/custom field

  • Hi all,

    I`m looking to do something that should be pretty simple.

    Ive created a powershell script which, when i run from kaseya returns the following results to #global:psresult#





    I'd like to simply grab each line and drop it into a custom field but i only seen to be able to find ways to drop the entire output to a single customer field.  Any ideas?

  • The easiest way will be to run four powershell scripts (or the same script with different parameters) so that it returns only line of text with each run. Agent procedures themselves can't do much string parsing or manipulation.

  • It's a bit of a kludge, but check out the "Agent Functions" procedures in the Automation exchange.


    With that  you could use the "readline" function to read individual lines to parse out that info..  I'd like to think that eventually Kaseya might provide some of these functions in the base product rather than this workaround, but in the mean time, these functions actually work relatively well once you get the hang of how to use them.

  • I also have a kludge solution that allows you to take a single string and split it into multiple values

    First I generate a variable that contains a string , this could by by reading a file content , or any method that allows you to form the base variable in the following format


    Each var is seperated with a "|" symbol

    Then in Kaseya I execute a  SQL query where I can pass to it either a Single String , a Double String or a Triple String

    So to split "StringA|StringB|StringC" into 3 variables I would execute the following 3 SQLReads

    3VarSplit1st  This will return StringA

    3VarSplit2nd  This will return StringB

    3VarSplit3rd  This will return StringC

    This is the SQLRead XML File for the SQL required

    <?xml version="1.0" encoding="utf-8" ?>


    <queryDef label="2VarSplit1st" sql="select left(#PromptValue#,charindex('|',#PromptValue#)-1)"/>

    <queryDef label="2VarSplit2nd" sql="select right(#PromptValue#,len(#PromptValue#) - charindex('|',#PromptValue#))"/>

    <queryDef label="3VarSplit1st" sql="select left(#PromptValue#,charindex('|',#PromptValue#)-1)"/>

    <queryDef label="3VarSplit2nd" sql="select SUBSTRING(#PromptValue#,charindex('|',#PromptValue#)+1,charindex('|',#PromptValue#,charindex('|',#PromptValue#)+1) - charindex('|',#PromptValue#)-1)"/>

    <queryDef label="3VarSplit3rd" sql="select right(#PromptValue,len(#PromptValue#) - charindex('|',#PromptValue#,charindex('|',#PromptValue#)+1))"/>