I have a very strange problem.
A powershell script is to start an exe. It works fine when run manually (right-click > run) or via script call in the powershell console. However, when I create a task in the task scheduler, it does basically create a process with the proper name, but the process is empty and does not do anything. It requires no CPU, the program is not listed in the task bar and the program window does not open. The script basically only contains:

Start-Process -FilePath <Path to exe>

I also tried:

& <path to file>

but that didn't work either. The task starts the program powershell.exe with the parameter

-ExecutionPolicy Unrestricted -Command "& C:\Scripts\MyScript.ps1"

I run it as an admin user and also tried "run with highest privileges" checked. That did not help either.

When I run the task and then start the program manually, it results in two separate processes with the same name but different handles. Usually only one instance of the program can run.

This is apparently a problem with the task scheduler, since the script works fine if run manually. Can anyone help me here?

  • When you say Task Planner I'm going to assume you mean Task Scheduler. If that is not the case then you will need to explain what the Task Planner is. Assuming that though, do you have the task set to run in your user context? – EBGreen Jun 7 '18 at 12:37
  • @RatticalRed Here's how I think you need to set it up in Task Scheduler... 1. on the General tab be sure both Run whether user is logged on or not and Run with highest privileges and 2. from the Edit Action in the Program/script field be sure you have PowerShell, in the Add arguments field have -ExecutionPolicy Bypass -File "C:\Scripts\MyScript.ps1" and in the Start in field have C:\Windows\System32\WindowsPowerShell\v1.0 .... let me know if this helps but that is what works for me Screen shot --> i.imgur.com/T11RnU5.png – Pimp Juice IT Jun 7 '18 at 22:25
  • Also when you go to save this job since from the General you have Run whether user is logged on or not it will prompt you for the username and password to run this job as so be sure that this account has permissions to execute the PS script and to execute the executable file the PS script will execute. If you decide to not user that option but only use the Run with highest privileges then it'll launch only when the account that you schedule it in Task Scheduler is logged on so if that's the one that works when you double-click and sufficient, that'll work too though – Pimp Juice IT Jun 7 '18 at 22:29
  • Your issue is more than likely the points and settings per #2 that I indicated above but when you used the -Command "& <PS Script>" that's more the way you want to do it if a batch is running your PS script so just configure the fields, etc. as per the #2 points in particular and that should resolve the issue for you. This works very reliably for me. – Pimp Juice IT Jun 7 '18 at 22:32
  • Hello EBGreen, thank you for your reply. First, I apologize for the confusion. Yes, I do mean Task Scheduler, the planner was a translation error. I edited the post accordingly. I did adjust the settings the way you wrote, however there was no change, the symptoms remain the same. – Rattical Red Jun 8 '18 at 8:35

I have run into what sounds like a very similar issue. Normally the application I had this issue with would open and begin processing a queue of files. In this case, as you described, it would sit completely idle when run from a scheduled task. Ultimately what worked was a batch file called from the scheduled task that then called the .ps1 that launched the .exe.

The lines in the batch file look like below and is called from the scheduled task with settings matching your description. LaunchProcess.ps1 in my setup contains a standard start-process for the exe. I haven't used this past 2008r2 server but I imagine works all the way up current.

batch file filename = restartProcess.bat

SET ThisScriptsDirectory=%~dp0 SET PowerShellScriptPath=%ThisScriptsDirectory%LaunchProcess.ps1 PowerShell -NoProfile -ExecutionPolicy Bypass -command "& {start-process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";

  • Hello 2manygadgets, thank you for your answer. Having the scheduler run a batch that starts the powershell file is a good idea. However, I tried it just now, and the same thing happens. One might think that since the scheduler only runs the batch and does not touch the ps1, it should be fine, but it isn't. When I start the batch normally, it works. However, when I have the scheduler run it, the symptoms are the same as in the original post. – Rattical Red Jun 8 '18 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.