How To Set Task Scheduler To Run PowerShell Script?

Windows Task Scheduler is used to schedule tasks according to different time options like hourly, daily, weekly, monthly, only once, etc. PowerShell scripts are used to run single or more PowerShell commands for different tasks. Running the PowerShell scripts is very useful as they can be used to take backup, add, remove, edit user, mount a file share, etc.

Create PowerShell Script

First, we create a PowerShell script that is executed at the specified conditions like every hour, every morning at 8:00, or every month. We will use the following PowerShell script which is created for simple backup. It simply compresses the C:\Data folder and put the compressed file into the D:\ . But you can use any command according to your situation. We will save this script file with the name of Backup.ps1 .

Write-Host "Backup Starting"

Compress-Archive -Path C:\Data -DestinationPath D:\

Write-Host "Backup Finished"

Create Task with Task Scheduler

In this step we will open the Task Scheduler in order to schedule the PowerShell script named Backup.ps1 . The task scheduler can be opened in different ways. The most basic and easy way is using the Start menu. Just open the start menu and type task scheduler . This lists the task scheduler like below.

Open Task Scheduler

Alternatively the Windows Run can be used to open the Task Scheduler. First open Windows Run screen with the WIN+R keyboard shortcuts. The command taskschd.msc is used to open Task Scheduler.

The followin screensot is about the Task Scheduler first or main screen. From the left panel click to the Create Basic Task .

Create Basic Task via Task Scheduler

The Create a Basic Task screen starts like below. We set the Name of the task and provide some description about the task. The description is optional and can be omitted.

In this second step, we select the trigger condition or interval like Daily , Weekly etc. We can set the time when the PowerShell script is executed.

Create Basic Task Wizard for Execution Interval

In this step, we set the execution time for the daily interval. Also the Recur every configuration is used to set a number of recurring times.

Create Basic Task for Specified Time

One of the most important part is this step. In this step the action type for the scheduled task is specified. As we want to execute PowerShell script and set the Start a program .

Set Scheduled Task To Start a Program

In this set, we set the Powershell script path. The Browse button is used to specify the PowerShell script in order to get the complete PowerShell script path. Also the Add arguments (optional) option can be used to provide an argument to the script.

The following screen is the last screen where the overview information about the scheduled task is displayed.

See also  PowerShell "Running script is disabled on this system" Error and Solution

Leave a Comment