Now Reading
How to create a scheduled task in windows

How to create a scheduled task in windows

Views  
views
21

Microsoft windows provides an ability for the user to schedule the launch of a program or script at pre-defined time or when one or more conditions are met using a Task scheduler component.

User gets an ability to define the conditions like when the hard disk space is 80% consumed, run a cleanup script or send an email to list of users. In this blog, I am sharing the steps to launch a logs cleanup powershell script as a scheduled task.

Ads

  1. Open the Windows Task Scheduler in the Start menu, under Start > Administrative ToolsScheduledTask1
  2. In Task Scheduler, select the Create Task option under the Actions heading on the right-hand side.
    ScheduledTask2
  3. Enter a name for the task, and give it a description (the description is optional).
  4. In the General tab, go to the Security options and specify the user account that the task should be run under. Change settings so the task will run even if the user is not logged in.
  5. Next, select the Triggers tab, and click New to add a new trigger for the scheduled task. This new task should use the “On a schedule” option. The start date can be set to the desired time, and the frequency and duration of the task can be set based on your specific needs. Click OK when your desired settings are entered.
  6. Next, go to the Actions tab and click New to set the action for this task to run. Set the Action to Start a program.
  7. In the Program/script box enter “PowerShell”
  8. In the Add arguments (optional) box enter the value “.\[Your PowerShell Script Name].” For example, if your PowerShell Script is named “TestScript.ps1” then you would enter “.\ TestScript.ps1” as the value.
  9. Then, Start button in the (optional) box, add the location of the folder that contains your PowerShell script. In this example, the script is in a folder called “Script” that is off the root C: drive.
    Note: The location used in the Start in box will also be used for

    1. storing the scheduled task run times
    2. the job history for the copies
    3. any additional logging that may occur.
  10. Click OK when all the desired settings are made.
  11. Next, set any other desired settings in the Conditions and Settings tabs.
  12. Once all the desired actions have been made (or added), click OK. The task will be immediately set, and is ready to run.
  13. To check if the task is set properly, right-click on the task and hit “Run”
View Comments (0)

Leave a Reply

Your email address will not be published.

Scroll To Top