Scripting the Task Scheduler to Create System Restore Points

I ran into an interesting situation the other day: I had a hard drive that was going bad, and thankfully I had most of my data backed up on a schedule. However, before I removed the old hard drive, I wanted to log into the system to double-check a few settings. Unfortunately, several of the operating system files had become corrupted and the system wouldn’t boot.

I didn’t think that was a big deal, because I could try a system restore. However, I had forgotten that Windows 10 creates far less restore points than previously, so I had fewer to work with. In the end, I wasn’t able to boot the system that final time.

Now that I have my newly rebuilt computer up and going, I set out to create a scheduled task that will create system restore points on a schedule. However, I wasn’t content to create the task; I wanted to create the task using a batch file script so I could easily run the script to create the same task on any new systems that I might build.

It took me a while to get the script parameters the way that I wanted them, but the following one-line script achieves everything that I wanted to do. Note that you need run this script in an elevated command prompt, otherwise it might fail with an access denied error.

schtasks.exe /create /tn "Create Restore Point (MONTHLY)" /sc MONTHLY /d SUN /mo FIRST /st 05:00 /rl HIGHEST /ru "NT AUTHORITY\SYSTEM" /tr "PowerShell.exe -ExecutionPolicy Bypass -Command \"Checkpoint-Computer\" -Description \"AUTOMATIC-$(Get-Date -Format \"yyyyMMddHHmmss\")\" -RestorePointType \"MODIFY_SETTINGS\""

Here are the different parts of that script in detail, so you can modify them for your situation:

schtasks.exe This is Windows’ command line application for managing scheduled tasks.
/create Specifies that we will be creating a scheduled task.
/tn "Create Restore Point (MONTHLY)" Specifies the name for the scheduled task.
/sc MONTHLY Specifies the schedule type, which could be MONTHLY, WEEKLY, DAILY, HOURLY, etc.
/d SUN These two parameters work together to specify how often the task runs, and the options for these values will depend on the schedule type. In this example, it is specifying the FIRST SUNDAY of each month.
/mo FIRST
/st 05:00 Specifies the starting time in 24-hour format.
/rl HIGHEST Specifies the "run level," which in this example is the highest level.
/ru "NT AUTHORITY\SYSTEM" Specifies the user account to run the task as, which in this case is "NT AUTHORITY\SYSTEM".
/tr "<<SEE BELOW>>" Specifies the command to run inside the task. The actual command in this example is somewhat complex, so I’ve broken it down in the following table. Note that this command needs to be within a pair of quotation marks; if you need to include quotation marks for the values inside this script, you will need to escape those characters as I have done in this example.

And here are the parameters for the task that is going to run as part of the task:

PowerShell.exe The application that we're running in this application is PowerShell.exe, because PowerShell has a cmdlet to create a restore point.
-ExecutionPolicy Bypass Specifies the execution policy, which in this example specifies that nothing will be blocked and there are no warnings or prompts.
-Command "Checkpoint-Computer" Specifies the PowerShell cmdlet that creates a system restore point, which takes the following two parameters.
-Description "AUTOMATIC-$(Get-Date -Format \"yyyyMMddHHmmss\")"

Specifies the description of the system restore point, which in this example invokes another PowerShell cmdlet to specify a date/time stamp that will show when the restore point was created. The restore points created by this task will look like “AUTOMATIC-20211201015150.”

-RestorePointType "MODIFY_SETTINGS" Specifies the type of restore point, which could be APPLICATION_INSTALL, APPLICATION_UNINSTALL, DEVICE_DRIVER_INSTALL, MODIFY_SETTINGS, or CANCELLED_OPERATION.

That's about all there is to it. In a sense, this task is a bit of a script hack by invoking PowerShell cmdlets via the command line, but it works. And at the end of the day, that's all that matters.

Here are a few additional resources that provide more detail on the commands that I was using to create this script:

I hope this helps!

Those who can - do. Those who can't - teach.

A few years ago I elected to take a class at the University of Arizona as a refresher for a programming language that I hadn't used in over a decade. I was originally self-taught in the language, and I knew that the language had evolved since I had last used it, so I thought that it would be worthwhile endeavor to study it formally.

The class was going well, but when I turned in one of my assignments, the professor had dropped my grade a full letter because - seriously - he didn't like my variable names. Being an adult - and not an 18-year-old that's fresh out of high school - I have no problems confronting an academic when I think they're incorrect. In addition, as someone who has been in the software industry for years, I have no problems calling BS when I think it's warranted.

I scheduled a time to meet with my professor, whereupon I told him that I thought he was wrong. All my variables were descriptive of their purpose, and I used a consistent format across the entire assignment. In addition, I wanted my grade restored.

The professor looked at me and said, "No one names variables like that."

I replied, "That's called 'Hungarian Notation.' It's a widely-used standard in the software industry."

He attempted to counter with, "That's outdated. No one uses that anymore."

To which I replied, "I work for Microsoft. We write millions of lines of code every day using that notation."

He grumbled a bit more, but eventually he acquiesced and restored my grade.

I later discovered that this particular professor earned his BS in Computer Science, then his Master's, then his Doctorate, and then went straight into teaching at higher education establishments. In other words, he's never worked a single day in the industry that he is teaching about, and yet somehow the software engineers of tomorrow are supposed to learn from him?

The Internet Is Down

You know, for all those hundreds of times that my kids would tell me "The Internet is Down," today the Internet actually goes down and none of my kids lived at home to complain about it. I'm not sure if that was a good thing or a bad thing...

Confused smile


FYI - For news about the Internet outage, see the following URLs:

Windows XP... Really?

This was an advertisement on Facebook today - seriously? Asking people to "upgrade" to Windows XP? That's like asking smart phone users to upgrade to rotary dial.

Upgrade To Windows XP