1

I have a simple batch file which calls a powershell script.

I've looked at the following 3 previous questions on the subject as well:

Run a batch file from Task Scheduler is not working with a java command

Windows Task Scheduler doesn't start batch file task

Task Scheduler not executing batch (bat) file with MSTest commands

It seems like I've tried every single combination of running the task and it still doesn't execute my powershell script.

batch file contents: powershell.exe "E:\SIS\fileCopy.ps1"

If I run the command in the batch file manually, it runs just fine. Here are things I've tried to do to get it working:

  • I've change the Security options to run as System with "Run with highest priveleges" checked
  • I've tried every other combination of "Run only when user is logged on", "Run whether user is logged on or not" and "Run with highest priveleges"
  • I've tried adding the "Start in (optional" setting to the folder where the files are located.

I'm at my wits end and can't believe Microsoft hasn't figured out a way to make this easier.

Community
  • 1
  • 1
Geoff Dawdy
  • 886
  • 6
  • 15
  • 42

3 Answers3

1

You need to have task scheduler execute Powershell.exe and have the arguments be the path to your .ps1 file.

To validate your script is running properly, you should set the Security options to 'Run only when user is logged on'. It will then pop the powershell dialog when it runs. I often also use start-transcript to view the results of scheduled poweshell scripts.

After you validate the script is running correctly, you can set the security options however best fits your situation.

Apothis
  • 406
  • 3
  • 7
  • I can't believe this actually worked. Here I am trying to run a batch file to run a powershell script. Hopefully this makes it onto the google search results along with the other questions on this topic. – Geoff Dawdy Aug 21 '14 at 21:21
  • Glad it's working. Powershell is your replacement for the command prompt. It seems many people have not leveraged it's abilities enough to realize that. – Apothis Aug 21 '14 at 21:22
0

Use the execution policy flag to flag that instance to unrestrisicted because your powershell settings may be blocking script execution. powershell -executionpolicy unrestricted -Command "E:\SIS\fileCopy.ps1"

0

I found that Task Scheduler can't run a batch file if it lives in a folder that is being synced by OneDrive. I had to move the batch file to another folder to get Task Scheduler to be able to run it.

Matthew
  • 1,630
  • 1
  • 14
  • 19