Galen H
Galen H

Reputation: 65

Windows Task Scheduler -- Fails to run Powershell Scripts

I have written two powershell scripts that I need to run every morning. The first generates a text file of the names and location of all of the new files added to a directory within the last twenty-four hours. The second script that I wrote takes that .txt file and e-mails it to myself.

Both of these scripts run perfectly when executed manually. I added them both to the task scheduler but the scheduler does not properly execute the scripts. The text file does not get generated, and the e-mail does not get sent.

Things that I have done (for both scripts):

  1. Selected the option to run whether user is logged on or not.
  2. Set to run with the highest privleges
  3. Have checked and rechecked that my ExecutionPolicy is Unrestricted.

Here is a picture of the task scheduler at the moment

Edit: Since that picture is so small here is a direct link: http://imgur.com/EX7Vxj7

Upvotes: 1

Views: 1773

Answers (2)

kekimian
kekimian

Reputation: 947

If your script is located on a shared map you need to provide unc to the file like this:

\\servername\script.ps1

You can find more details in this post: https://dmitrysotnikov.wordpress.com/2011/02/03/how-to-schedule-a-powershell-script/

Upvotes: 0

Deadly-Bagel
Deadly-Bagel

Reputation: 1620

The Action needs to be set to "Start a program" and the program should be PowerShell.exe

Secondly in the Add Arguments box you need to enter -File '[script path]'. You can add -NoExit if you want to keep the window open afterwards but it will need to be running as your own user of course.

Upvotes: 1

Related Questions