Reputation: 906
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'm at my wits end and can't believe Microsoft hasn't figured out a way to make this easier.
Upvotes: 1
Views: 1351
Reputation: 1807
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.
Upvotes: 0
Reputation: 19
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"
Upvotes: 0
Reputation: 426
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.
Upvotes: 1