This seems simple in a vacuum, but not in practice.
We have a custom view which lists all currently online non-server endpoints with an uptime of 14 or more days. Without an automated system that reboots offending endpoints, we would expect this view to grow in size over time. To reduce the number of endpoints in the view, something will need to tell the endpoints to reboot. Creating a policy for that view to run a "Reboot" agent procedure seems like a good idea, right? Well—there is no logic in the scheduling module that can tell the endpoint to reboot "at 2 AM tonight", or any time for that matter. It's static, not dynamic. I can schedule the agent procedure to run tonight at 2:00 AM, sure. But tomorrow, endpoints will reboot the second they exceed the 14 day threshold, as the agent procedure was scheduled to run in the past (last night).
My workaround was to create a PowerShell script that will inject a scheduled task to reboot the computer on the same day the script was ran, at 11:59 PM. This does work, except, obviously it only works on Windows OSes. That's only 90% of our managed endpoints. This means Macs and Linux endpoints can't run the script, and thus cannot reboot on the night they exceed the threshold.
Am I totally missing something here, or is what I'm trying to accomplish actually not possible?
IN my experience with policies, an agent procedure scheduled to run in the past will actually not run for at least 24 hours after the policy applies, unless that's changed recently. So for example If I scheduled something to happen at 2:00am days ago, it ends up scheduling it for 2:00am tomorrow after the policy applies. Honestly I'd be happy to be wrong about that, as we have a lot of things that we'd like a machine falling into a policy view to trigger *immediately* when it falls into the view.
Add into your Agent procedure a step that does a time check
E.g. echo time/t to a variable and check the result
I use a small bit of vb to strip all the ":" and AM/PM etc from the result so if I ran this command at 3:30 AM the variable I get is just 0300
If I ran it at 12:45 PM I get 2445
You can also do this with a simple SQL NonQuery
So what I do is
Via Policy/View etc I run the script
It checks the current time of the Endpoint and saves as variable #CurrentTime#
It then used 2 nested if statements e.g.
If #Currenttime# >= to 0200
If #Currenttime# < to 0300
Then "reboot Endpoint"
"Reschedule Procedure to run again in 30 min"
If the test determines the current time is between 2 an 3am it reboots
If not it just reschedules the same script to run again in 30mins time
So lets say the script 1st triggers at 11:22pm ..
It will not reboot and will run again
At 11:52pm will not reboot
At 12:22pm will not reboot
At 1:22am will not reboot
At 1:52am will not reboot
At 2:22am it will reboot and script exits
Or you can just use a WMI query to derive a time variable
And append the 2 values together
hewres an example of my script using wmi