Creating a scheduled task on very large number of servers? Why not using a PowerShell script to do the job, using the “ScheduledTasks” – module. Lets make the module visible and point the various functions to the correct part of the task scheduler.
When taking a closer look at the module, following functions are included.
We will discuss here only the functions that are needed to created a proper scheduled task on a your Windows machine. Lets go ahead and define the various functions of the module:
- New-ScheduledTaskAction – function is related to the “Action” tab
New-ScheduledTaskTrigger – function is related to the “Triggers” tab
New-ScheduledTaskPrincipal – function is related to the “Security Options” in the “General” tab.Information: link
Register-ScheduledTask – function will be used to add the Scheduled task to the task scheduler. More information see link
Register-ScheduledTask [-Force] [[-Password] ] [[-User] ] [-TaskName] [[-TaskPath] ] [-Action] <CimInstance> [[-Description] ] [[-Settings] ] [[-Trigger] <CimInstance>] [[-RunLevel] ] [-CimSession <CimSession>] [-ThrottleLimit ] [-AsJob] 
#Import Module ScheduledTasks Import-Module -Name "ScheduledTasks" #Define the task action parameters. $Sta = New-ScheduledTaskAction -Execute "powershell" -Argument ".\TestScript.ps1" -WorkingDirectory "C:\Scripts\" #end #Define the task trigger parameters. Task will start daily at 01AM. $Stt = New-ScheduledTaskTrigger -Daily -At 1am #end #Define the task principal $Stp = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest -LogonType ServiceAccount #end #Variable includes description/TaskName for the scheduled task. $StTaskName="TEST SCRIPT 01" $StDescript="Schedule task that will launch a test script on the local machine" #end #Register the task in task scheduler. Register-ScheduledTask -TaskName $StTaskName -Action $Sta -Trigger $Stt -Principal $Stp -Description $StDescript #end
After running the script you will find a new task is the task scheduler.
Have fun creating your scheduled tasks in a wink.