In System Center Configuration Manager (ConfigMgr) 2007 and beyond, the time that a program for a required deployment is enforced (or run) by the client is generally thought to be the assignment schedule time(s) defined within the deployment.
As discussed in my Recurring Advertisements post, this isn’t exactly the case though. Basically, if a client misses an assigned time for whatever reason, it will catch up meaning that it very well can run at just about any time after the scheduled time. As an example, if you schedule something to run every night at 10PM, like a shutdown or restart, and if the system is not on at that time, it will run the shutdown or restart when it is on again. This of course could be very disruptive to the end-user and bad for your reputation (not that we ever care about those things).
There are a couple of different ways to handle this:
- Use Maintenance Windows. This works quite well; however, maintenance windows will also affect every required deployment targeted at the system. This may be undesirable (or maybe not, that’s for you to determine). You can of course exclude deployments from maintenance windows, but you are now just creating work for yourself.
- Use a simple batch file to check the time and only execute the shutdown or restart if within a given time frame. Here is an example batch file to do just this. This is slightly more complex than simply running shutdown.exe because now you need to make the batch file available to the clients, but that’s par for the course with ConfigMgr software distribution and thus shouldn’t be of any actual concern.
@ECHO OFF set H=%TIME:~0,2% set M=%TIME:~3,2% set NOW=%H%%M% if %NOW% LSS %1 exit /b 0 if %NOW% GTR %2 exit /b 0 %windir%\system32\shutdown.exe /t 300 /g /d p:0:5 /c "Restart initiated by ConstrainedReboot script via a ConfigMgr deployment."
To use the above, copy and paste it into a batch file, place this in your content library, create a package referencing the folder where you placed it, and create a program with the following command-line:
ConstrainedReboot.bat 2200 2300
The two parameters after the batch file name are the times (in 24 hour format) in between which (inclusive) that you want the action to happen — line 11 defines the actual action that you would like to happen within the times specified. Outside of these times, the batch just exits gracefully. Make sure that the schedule time(s) for the deployment fall within the time range specified otherwise the action will ever actually be run. And of course, the shutdown.exe command above is just an example and you can change line 11 to be anything you want or need it to be.
Note that there are other ways to possibly address this scenario (like using a task sequence and WMI conditions) but these just add complexity to the process so I won’t detail them here and recommend you stick with #1 or #2 above.