How to run a PowerShell script that exports SQL data on a schedule using Task Scheduler

Home > Search > How-to
  by

This assumes you have created a PowerShell script that exports data from SQL. Follow these directions to automatically run this script using Task Scheduler.

  1. Select the Windows Start icon, type task in search, and select Task Scheduler
  2. On the right side of the Task Scheduler, select Create Task
  3. In the Create Task dialog box, make the following entries:
    1. 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
    2. Triggers Tab
      • Select New
      • Schedule the task to run today, just a few minutes in the future.
    3. 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
    4. Conditions Tab
      • Remove the check from Start the task only if the computer is on AC power 
    5. 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 
    6. Select OK
  4. 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.

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments