This creates a task that works and writes to a file:
schtasks --% /create /tn "test" /sc minute /mo 10 /ru SYSTEM /tr "powershell get-date | out-file -Encoding:ascii c:\log.log"
This does not create a log file and i cant see any errors:
schtasks --% /create /tn "test2" /sc minute /mo 10 /ru SYSTEM /tr "powershell someexe --help | out-file -Encoding:ascii c:\otherlog.log"
The second command isn't writing to the log file, why? Even if it fails it should still be writing to the file. If I run this from the command line it still writes to the file:
PS C:\> powershell doesntexist --help | out-file -Encoding:ascii c:\fail.log
PS C:\> cat .\fail.log
doesntexist : The term 'doesntexist' is not recognized as the name of a cmdlet, function, scrip
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ doesntexist --help
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (doesntexist:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
So I cant understand why the first task is writing to a file and the second one is not