Reboot a computer with Scheduled Task

I’m trying to have a reboot occur at a particular time after patching has been applied on a machine. I want the machines to reboot at 8:10am, after giving the users a 5 minute warning, in case they are on. If the patching completes before 8am, I’d like the reboot to happen today at 8:10am, otherwise, happen tomorrow at 8:10am

Here is the code I am trying to use to set the Scheduled task to perform the reboot:

if {two digit hour of it of time (local time zone) of now as integer < 8}
parameter “run_date” = “{(month of it as two digits & "/" & day_of_month of it as two digits & "/" & year of it as string) of current date}” 
else
   parameter “run_date” = “{(month of (it + 1*day) as two digits & "/" & day_of_month of (it + 1*day) as two digits & "/" & year of (it + 1*day) as string) of current date}”
endif

   dos schtasks /create /ru system /rl highest /sc once /tn reboot_8am /tr "shutdown /r /f /t 300 /c \"Testing your computer and a 8:10am reboot has been scheduled. PLEASE SAVE ALL WORK prior to the reboot."" /sd {parameter “run_date”} /st 08:05 /F

Eventually, I might include a file that contains the time to perform the reboot, so the same action can be applied to a group of machines, and that file will be used to determine the time of reboot.

Any help would be great,

Bob_K

I’m not sure of the question, is some part of this not working?

@JasonWalker

Sorry, line 2 is showing as failed

Fixlet Debugger shows:

parameter add failed

Thanks,

Bob_K

That relevance seems to work for me. A couple of things I’d check -

  • Is it using the correct doublequotes? Here in the forum it’s showing as “Smart Quotes”, which can happen if you’ve copied/pasted from a Word doc for example.
  • Has the “run_date” parameter already been defined earlier in the actionscript? A parameter can only be defined once, it cannot have its value updated later in the script.

@JasonWalker

Smart Quotes was the issue!

I should know better than copying and pasting from a MS product (Outlook). I had emailed some code, and then cut and pasted from there.

What I usually do is cut and paste it into notepad, and then cut and paste it from there to get rid of that “stuff”.

Thanks,
Bob_K

1 Like