Windows Task Scheduler - Run a PowerShell script that exports SQL data on a schedule

by
Jeremy Canfield |
Updated: March 12 2020
| Windows Task Scheduler articles
This assumes you have created a PowerShell script that exports data from SQL. Follow these directions to automatically run this script using Task Scheduler.
- Select the Windows Start icon, type task in search, and select Task Scheduler
- On the right side of the Task Scheduler, select Create Task
- In the Create Task dialog box, make the following entries:
- General Tab
- Give this task a name, such as PowerShell Export SQL Server to TXT
- Bullet Run whether user is logged on or not and check Do not store password
- Check Run with highest privileges
- Triggers Tab
- Select New
- Schedule the task to run today, just a few minutes in the future.
- Actions Tab
- Select New
- Keep the action as Start a program
- In Program/script, type powershell.exe
- In Add arguments, type /f "C:\path\to\script.ps1
- Leave the Start In box empty
- Select OK
- Conditions Tab
- Remove the check from Start the task only if the computer is on AC power
- Settings Tab
- Check Run task as soon as possible after a scheduled start is missed
- In Stop the task if it runs longer than, set the drop-down to 1 hour
- Select OK
- General Tab
- Select OK to save the Task
In the left panel of Task Scheduler, select Task Scheduler Library, and the newly created DTSX Task will be listed in the list of tasks. Before the task is run for the first time, Last Run Time will be never. After the task schedule has passed, right-click on Task Scheduler Library and select Refresh. The Last Run Time should display the time the task was run. Navigate to C:\Users\<username>\PowerShell_Scripts\ and open the sql_server_ssis.txt file. Ensure the text file contains the date/time the task was scheduled to run.
Did you find this article helpful?
If so, consider buying me a coffee over at