Kaseya Community

Getting variable info from agent procedure

This question is answered

Hi all,

(This is just a experiment, this is not applied to live environment as i wanted to first understand this concept, then only apply some other agent procedure)

My plan is to do the following:

Extract a results from CMD to update it to the custom field at audit section there.

Example: I want to get the original install date of the OS, so in my agent procedure:

1- Execute command shell: systeminfo | find /i "install date" (I am not writing the full line, just a short cut of it)

2- (I need help on this one, to extract the info out from the command, or if its only done by exporting it to txt first)

3- Update system info .....and so on...

Please help at step number 2 ...see what is best procedure to be used.

Thanks

Verified Answer
  • Hi  

    The easiest way to achieve this would probably change the 1st step from execute shell command to execute shell command to variable step.

    Whatever the output of the command is will be used in #global:cmdresults# variable, which can be used to update the custom field;

    This could be done in a number of different ways. This is just one path you can take.

All Replies
  • Simplest answer, if you have the actual output from the command line you want:

    executeShellCommandToVariable("systeminfo | find /i "install date"")

    updateSystemInfo("CustomField", "#global:cmdresults#")

    If you actually need to parse the output of your command line first, I strongly recommend PowerShell. In PowerShell you can use full string functions to search, split, and parse text significantly easier. For example use this agent procedure:

    getVariable(Agent Working Directory, temp)

    writeFile(VSASharedFiles\GetData.ps1, #temp#\GetData.ps1)

    executeFile(%SYSTEMROOT%\System32\WindowsPowershell\v1.0\powershell.exe, -nologo -executionpolicy bypass -noprofile -file "#temp#\GetData.ps1" -OutputFile "#temp#\output.txt")

    getVariable(fileContents, #temp#\output.txt, output)

    updateSystemInfo("CustomField", #output#)

    Then use a PowerShell script similar to this (GetData.ps1):

    Param (

       [String]$OutputFile

    )

    [String]$sysInfo = & systeminfo

    if ($sysInfo.Contains('install date')) {

       $results = $sysInfo.Substring($sysInfo.IndexOf('install date'), 12)

    } else {

       $results = 'Not Found'

    }

    $results > $OutputFile

  • output the cmd to txt and read that in to a kaseya variable.

    i.e. systeminfo | find /i "install date" >> C:\temp\install.txt

  • Hi, if you search the forums for 'os install date' you'll find this has been covered before and there are some working example scripts provided by community members.

    There are lots of options for your step 2 above. We're using 'execute shell command to variable' with the command below to extract just the date. If I was writing it again I'd probably use powershell.

    for /F "usebackq tokens=4 delims=, " %I in (`systeminfo ^| find "Original Install Date"`) DO @echo %I

  • A couple examples:

    Install Date

    You will need to create a custom field named: "Original Install Date "

    For Windows 7:

    For Windows 8

    Current Date and Time:

    Custom fields to be created:  Current Time and Current Date

  • Here's a simplification of what our RMM Suite provides:

    We run SystemInfo daily, sending the results to a file. A procedure is run and copies a VB script to the target system. The procedure then calls that script repeatedly, passing arguments that specify the data source and record ID. In this case it would be SysInfo,"Install Date". The script extracts the requested data from the defined source and returns it to the Kaseya procedure, which then stuffs it into a custom variable associated with that agent.

    A single Kaseya procedure deploys the script, runs the SystemInfo > SysInfo.txt as a shell command, and then runs pairs of commands that run script to get the data and then save the data in a field. The command that runs the VB script calls it via executeShellCommandToVariable(). Since SystemInfo takes some time to run, you don't want to run it multiple times. Send the output to a file, then just read the file over and over. Faster and less resource utilization. Once the VB script returns the data to a variable, just write it to a custom field.

    My program is more complex than the example above and can be given multiple arguments that define the source data - but the basic concept is the same. I don't use Kaseya to process the data, just to request and store it.

    For example, I can provide the following args to my program to request data from different sources:

    SI,Data to extract a record from the SystemInfo file

    RI,Data to extract a record from the RMMInfo file that some of our maintenance tools populate

    REG,Key,Value to extract data from the registry

    INI,File,Section,Value to extract data from an INI or INF file.

    We pull about 40 items from every agent every day as part of daily maintenance and keep the information up to date on around 2500 endpoints.

    More info on www2.mspbuilder.com/.../rmmsuite

    Glenn

  • Hi  

    The easiest way to achieve this would probably change the 1st step from execute shell command to execute shell command to variable step.

    Whatever the output of the command is will be used in #global:cmdresults# variable, which can be used to update the custom field;

    This could be done in a number of different ways. This is just one path you can take.

  • Hey Nicholas,

    Thank you very much for your help :D

    It works!

    So now i think i got some even bigger idea on what to use with the #global:cmdresults#

    Have a great day

    Best regards

    Aaron

  • Sorry my screenshots with the full procedures were removed.

  • Install Date:

    You will need to create a custom field named: "Original Install Date "

    executeShellCommandToVariable("systeminfo|find /i "install date"", "User", false, "All Operating Systems", "Halt on Fail")

    writeProcedureLogEntry("#global:cmdresults#", "All Operating Systems", "Halt on Fail")

    updateSystemInfo("Original Intall Date", "#global:cmdresults#", "All Operating Systems", "Halt on Fail")

    Current Date and Time:

    Custom fields to be created:  Current Time and Current Date

    executeShellCommand("time /T >> C:\Temp\time.txt", "Execute as User", "All Operating Systems", "Halt on Fail")

    getVariable("File Content", "C:\Temp\time.txt", "strTime", "All Operating Systems", "Halt on Fail")

    updateSystemInfo("Current Time", "#strTime#", "All Operating Systems", "Halt on Fail")

    executeShellCommand("date /T >> C:\Temp\date.txt", "Execute as User", "All Operating Systems", "Halt on Fail")

    getVariable("File Content", "C:\Temp\date.txt", "strDate", "All Operating Systems", "Halt on Fail")

    updateSystemInfo("Current Date", "#strDate#", "All Operating Systems", "Halt on Fail")