Kaseya Community

ShellCommand to check system time fails from agent procedure

This question is answered

What do I want to do?

I want to check the endpoint system time if it is between two values.

The procedure may only continue if the system time is between 23:00 and 05:00.

Note: I change the time in between tests with the dos command "time". You can see it in picture 1.

The CMD script that works (see picture 1 for results):

FOR /F "tokens=1-2 delims=:" %%a IN ('echo %TIME: =0%') DO SET CT=%%a:%%b
echo %CT%
IF %CT% LEQ 05:00 (set cont=YES1) ELSE (IF %CT% GEQ 22:00 (set cont=YES2) ELSE (set cont=NO))
echo continue? %cont%

 

The kaseya solution:

I have a procedure called '1 - variables' which holds two variables with values:

#GLOBAL:OHstart#  with value 22:00, and

#GLOBAL:OHEnd#  with value 05:00

I converted the command script to a kaseya procedure (see picture 2).

I do the same checks/steps only with the global kaseya variables.

The issue:

I print the results in a popup on the endpoint (see picture 3).

There is the problem visible. If the first check fails, the second check is not done (properly) and the result is just the time again, instead of an expected yes, yes2 or no.

What am I missing? Anyone can help me improve this?

Thanks, and have a great weekend!

 

Verified Answer
  • Hello Maurice,

    Besides the fact as you know, Kaseya procedures can be scheduled to run from the Agent perspective timezone / time I can show you this alternative.

    Make a procedure with 2 steps only.

    Step1 - Execute Powershell (save variable to global:psresult = true) with the below command:

    If (((get-date).TimeOfDay -ge '23:00') -or ((get-date).TimeOfDay -le '05:00')) {Write-Host 'True'} else {Write-Host 'False'}

    Make sure you don't change single quote with double quotes otherwise it will fail.

    Step 2 - IF

    If checkvar ("#global:psresult#) contains True

    Everything that goes below that if will only be executed if the time at the agent will be between 23:00 and 05:00.

    I have checked it and it works on my agent.

    Alex

All Replies
  • Hello Maurice,

    Besides the fact as you know, Kaseya procedures can be scheduled to run from the Agent perspective timezone / time I can show you this alternative.

    Make a procedure with 2 steps only.

    Step1 - Execute Powershell (save variable to global:psresult = true) with the below command:

    If (((get-date).TimeOfDay -ge '23:00') -or ((get-date).TimeOfDay -le '05:00')) {Write-Host 'True'} else {Write-Host 'False'}

    Make sure you don't change single quote with double quotes otherwise it will fail.

    Step 2 - IF

    If checkvar ("#global:psresult#) contains True

    Everything that goes below that if will only be executed if the time at the agent will be between 23:00 and 05:00.

    I have checked it and it works on my agent.

    Alex

  • YES! Thank you! I have been thinking around in circles for days now, now being able to see this.

    I tested it now (also with the global variables) and it works like a charm. Thanks again!

    In regards to the scheduling thing, I'm aware. But the task that will be running after this check is very disruptive so I want a double check in case of human scheduling error.

    Greetings,

    Maurice.