u936293
u936293

Reputation: 16214

Command runs fine on command line but not from Task Scheduler

PowerShell 2.0 on Windows 7 64-bit

When I tested out in a shell, the following works fine:

powershell -command { sleep 5 }     

But when I have this in a Scheduled Task, with powershell in the Program box and -command { sleep 5 } in the Argument box, Task Scheduler reports "The operation completed successfully. (0x0)" but nothing is run.

I had to record the screen with a video camera and then played back in slow motion to find out what is going on. After the PowerShell profile script runs, sleep 5 shows on the screen with no error and PowerShell closes immediately.

(Both my x86 and x64 versions have ExecutionPolicy set to RemoteSigned.)

What do I have to do to make -command work in Task Scheduler? .

Upvotes: 3

Views: 1993

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

Try powershell -Command "sleep 5" instead.

Upvotes: 4

Related Questions