0

I'm trying to learn about task scheduling in Windows 10, so I set myself the task of trying to schedule a script that writes a blank file called test.txt to the user's home directory.

I did this by creating a task that executes Out-File -FilePath $HOME\test.txt:

enter image description here

However, when I try to execute this task manually I see some errors:

enter image description here

I've also confirmed that the test.txt file wasn't created. The error description looks like this:

Task Scheduler failed to launch action "Out-File" in instance "{32b4ec9b-49e8-441a-852d-8332f0a118d5}" of task "\TestTask". Additional Data: Error Value: 2147942402.

According to another SF question This issue is caused by a "File Not Found" error. I thought maybe it couldn't find the Out-File command so I tried changing the command to echo "test" >> $HOME\test.txt but this didn't seem to have any effect.

What am I doing wrong here?

1 Answer 1

1

I really should have read the answer to the question I linked better: What causes scheduled task error 2147942402?

This answers my question:

The reason is that MOVE is not a program, but a native command in cmd.

It should be:

Program: "cmd.exe" Arguments: "/c move C:\Windows\Temp*.foo E:\Foo_blah_blah_blah_blah\Foo2"

In my case what I should have done was execute the command powershell.exe with the arguments -Command "Out-File -FilePath $HOME\test.txt", which works great.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.