Kaseya Community

Compare dates in a kaseya script

  • I have a script that Gets a variable based on the File last modified date of a particular folder file. Is there a way to then take that date, and compare it to todays date, then email if it is has not been updated in X days?

    Legacy Forum Name: Compare dates in a kaseya script,
    Legacy Posted By Username: Intech-Jordan
  • Maybe one of the more seasoned Kaseya scripters can help you but have you looked at doing it via a VBS?

    write a file on the temp folder like "datecheck.log" with the date you have from the variable. the vbs checks the file, reads the data and does a datediff with today's date and that one and saves the result to dateresult.log, and then the script can read that file..

    just an idea.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jmejia
  • You can do a test in the IF function by doing a test variable and using the built in system variable called CURRENTDATE to compare to a date you have picked up from a file, registry key etc.

    Here is a sample Agent Procedure:

    <?xml version="1.0" encoding="utf-8"?>
    <ScriptExport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.kaseya.com/vsa/2008/12/Scripting">
      <Procedure name="Date Test" treePres="3" id="1764639759">
        <Body description="">
          <If description="">
            <Condition name="CheckVariable">
              <Parameter xsi:type="StringParameter" name="VariableName" value="CURRENTDATE" />
              <Parameter xsi:type="EnumParameter" name="Condition" value="GreaterThanOrEquals" />
              <Parameter xsi:type="StringParameter" name="Value" value="28/03/2011 00:00:00" />
            </Condition>
            <Then>
              <Statement description="Display a message dialog to the user." name="SendMessage" continueOnFail="false">
                <Parameter xsi:type="StringParameter" name="Message" value="Time is Greater!" />
                <Parameter xsi:type="BooleanParameter" name="Immediate" value="False" />
              </Statement>
            </Then>
            <Else>
              <Statement description="Display a message dialog to the user." name="SendMessage" continueOnFail="false">
                <Parameter xsi:type="StringParameter" name="Message" value="Time is Less!" />
                <Parameter xsi:type="BooleanParameter" name="Immediate" value="False" />
              </Statement>
            </Else>
          </If>
        </Body>
      </Procedure>
    </ScriptExport>

     

  • Good to know about the "CURRENTDATE" variable, I know about the Database views but not about this one, are there any more of them that you can share?

    Also WMI values are good for this as you can break the date and time up into segments, this post I did a while back should help with the basics;

    community.kaseya.com/.../52642.aspx

  • The CURRENTDATE option looks easy to me.  I have tried writing it to a system info field using "CURRENTDATE" and "#CURRENTDATE#" and it doesn't work though.

    This is the extract from the XML file:

                 <Statement description="Update the selected System Info field with the specified value for the agent this procedure runs on." name="UpdateSystemInfo" continueOnFail="false" osType="Windows">

                   <Parameter xsi:type="StringParameter" name="ColumnName" value="Antivirus Definition Last Checked" />

                   <Parameter xsi:type="StringParameter" name="Value" value="CURRENTDATE" />

                 </Statement>