How can I troubleshoot Scheduled Task error 2147942401 when running PowerShell?
Asked by
MellowCedar47
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?
Answers
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.
Reply to this answer
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.
Reply to this answer
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.
Reply to this answer
Add your answer
Answers are reviewed before publication.
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.