Windows Task Scheduler example
Published 05 April 2017
This example shows how to schedule a SQL Clone task using PowerShell and Windows Task Scheduler. The example creates a new task that'll run daily and remove any images older than a week that have no clones.
Before you follow this example, make sure:
- The SQL Clone PowerShell cmdlets have been installed (these can be downloaded from the settings page in SQL Clone)
- The PowerShell script you'd like to schedule has been saved to a file. In this example we'll be using the script from Purge old images which don't have clones, which has been saved as D:\SQL Clone scripts\RemoveOldImages.ps1
To schedule a task:
Start Windows Task Scheduler by opening the Start menu and typing Task Scheduler.
Task Scheduler can also be opened using the Control Panel under System and Security > Administrative Tools > Task Scheduler
- Right click on the Task Scheduler Library and select Create Basic Taskā¦:
- Enter a name and optional description and click Next:
- Make sure Daily is selected and click Next:
- Select the time when you'd like to run the task and click Next:
- Make sure Start a program is selected and click Next:
Enter PowerShell as the Program/script and enter -File followed by the path to the saved PowerShell script under Add arguments and click Next:
If the path to the PowerShell file contains any spaces, make sure the path is enclosed in quotation marks.
- Select the Open the Properties dialog for this task when I click Finish check box and click Finish:
In the Properties window under Security options:
- verify that the user listed has permission to use SQL Clone
- select the option to Run whether user is logged on or not
- Press OK and enter the password for the user when prompted.