Create Multiple Scheduled Tasks with PowerShell

 


The more parameters are added, the more complex the manual creation of automatic timed-controlled tasks in Windows are. In the first part of my blog posting, I showed how to use the Windows Task Scheduler to run PowerShell scripts at specific times. 

However, if you want to create several, similar tasks that differ only in some parameters you may work differently. Microsofts provided Wizards is not the most efficient way to proceed. I will show you a way to create multiple scheduled tasks quickly and without a wizard.

Accelerate tasks with PowerShell

Once again, you can use PowellShell to speed up task creation. The following PowerShell cmdlets are available:

  • New-ScheduledTaskAction, to indicate which program to execute
  • New-ScheduledTaskPrincipal, to specify the user under which the task should be run
  • New-ScheduledTaskTrigger, to determine when something is executed
  • New-ScheduledTask, to aggregate the task
  • Register-ScheduledTask, to add this to the Task Scheduler

Here is an example script for the above use case:

The result should look like this:

Example Task PowerShell

Just adjust the script to create multiple scheduled tasks quickly.

Restrictions you should considered

This task creation script can only be run as an administrator!

The string following “-Command”  in the $ argument variable must be “escaped” for PowerShell. This can be achieved by using `<string>.

Individual configuration of a task

There are many ways to adjust the configuration of a task. Both are possible through the wizard and through the various cmdlet parameters. These are very well documented. It is important not to select “Create Basic Task” but “Create Task”.

Active Directory Delegation Powershell

Conclusion

For a single time-controled automation tasks, Windows task scheduling with the help of PowerShell is a very good option. However, manually creating these tasks can be really time-consuming. It also gets confusing in the wizard as soon as a PowerShell script has many parameters.

Remedy the fact that you do not actually need the Wizard, but can create multiple scheduled tasks via PowerShell. Here you have to make sure that the syntax of the argument is correct. Once you’ve done that, creating more tasks like this is no longer a problem. I hope this blog post helps overcome this initial hurdle. If you want to go forward with Powershell, you should have a look at our Recursive list of group members in AD or Import PowerShell sessions from computers in another domain article. 

Post a Comment

0 Comments