When you’re working with a computer, there are a few things you can do to make your life easier. One is to schedule tasks so that they’re done when they’re due. Another is to use the command line to schedule tasks. The command line is a great way to schedule tasks because it’s easy to use and it doesn’t require any input from you. To start scheduling tasks on the command line, you need to be logged in as an administrator. To do this, open the Windows PowerShell console and type: netstat -an | grep tcp | awk ‘{print $2}’ This will show you all of the active TCP connections on your system. You can then use the netstat -an command to find out which task has been scheduled for next time: netstat -an | grep tcp | awk ‘{print $2}’


While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:

Manipulate tasks in batch scripts. Control and create tasks on networked machines without having to login to them. Mass create/sync task across multiple machines. Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.

As you can probably imagine, the SchTasks command has more options than we can cover in this article so we are going to focus on showing some examples of common task configurations and what the respective task looks like in the Task Scheduler.

Examples

Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:

Modify ‘My Task’ to run at 2 PM:

 

Create ‘My Task’ to run C:RunMe.bat on the first of every month:

Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:

Delete the task named ‘My Task’:

Note: this will raise a warning which you will need to confirm.

Bulk Creation

Like any other command line tool, you can include multiple instructions in a batch file to accomplish bulk creation (or deletion).

For example, this script:

Produces these tasks:

The ability to do this is a quick way to roll out new tasks or change existing schedules to many machines at once. As a way to ensure the tasks are updated, you could include the appropriate SchTasks commands in a domain login script which will update user machines when they log in.

Microsoft Documentation on SchTasks Command