How can I troubleshoot Scheduled Task error 2147942401 when running PowerShell?

0
2
Asked By MellowCedar47 On

I created a Windows Scheduled Task to run a PowerShell script, but it fails with error 2147942401. The action currently uses `C:WindowsSystem32WindowsPowerShellv1.0powershell.exe` with these arguments: `-executionpolicy bypass -file "C:Path_to_ScriptScript.ps1"`. The script runs successfully when launched manually, including under the service account used by the task. It accesses a UNC path and deletes files older than a specified date. Is the action configured incorrectly, or is there something else I should check?

3 Answers

Answered By OrbitingPanda8 On

That error maps to `0x80070001`, or `ERROR_INCORRECT_FUNCTION`, but the message alone doesn’t identify the exact cause. Try setting the task’s **Start in** directory to the script folder. You can also use `powershell.exe` as the program and pass `-ExecutionPolicy Bypass -File "Script.ps1"` as the arguments. Add `Start-Transcript` or another form of logging to the script so you can see what changes when it runs under Task Scheduler.

MellowCedar47 -

The task runs under a service account with administrative access on the server and the target. The script works manually under both my account and the service account, but I haven’t set a Start in directory yet.

Answered By CopperLynx19 On

Because the script accesses a UNC path, check the scheduled task’s logon context rather than relying only on administrator rights. The account needs the appropriate **Log on as a batch job** permission and both share and NTFS access. If the script reaches another server or resource through a second network hop, credential delegation or an alternative authentication approach may also be required.

Answered By QuietHarbor62 On

Check the executable and every path involved. Using `powershell.exe` instead of the full path can help determine whether the executable path is the problem. Also verify that the service account can access the script directory itself, including all parent folders, and that the script file isn’t blocked if it was downloaded.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.