I created a Windows Scheduled Task to run a PowerShell script, but it fails with error 2147942401 (0x80070001, ERROR_INCORRECT_FUNCTION). The task uses C:WindowsSystem32WindowsPowerShellv1.0powershell.exe with these arguments: -ExecutionPolicy Bypass -File "C:Path_to_ScriptScript.ps1". The script runs successfully when launched manually, both under my account and under the service account configured for the task. It accesses a UNC path and deletes files older than a specified date. I have not configured the task's "Start in" directory. What settings or permissions should I check?
3 Answers
Try setting the task's Start in directory to the folder containing the script, such as C:Path_to_Script, and simplify the command to powershell.exe with arguments -ExecutionPolicy Bypass -File "Script.ps1". Also verify that the service account can access the script folder and every directory above it. Adding Start-Transcript to the script can help capture what happens when it runs unattended.
Because the script accesses a UNC path, make sure the scheduled-task identity can authenticate to that remote resource. Running it manually as an administrator does not prove the service account has the same network access. If another server is involved, investigate delegated credentials or a possible double-hop issue. Also check whether the script was downloaded and needs to be unblocked before PowerShell will run it.
The hexadecimal form of 2147942401 is 0x80070001, which means ERROR_INCORRECT_FUNCTION. That does not necessarily identify the exact problem, so check the executable path, argument quoting, working directory, and the account selected in the task. Confirm that the account has the Log on as a batch job right and that the task is configured to run with the intended privileges.

The task uses a service account with administrative access on the server and the target, but I will verify its batch-logon right and access to the UNC path specifically.