r/PowerShell • • Aug 07 '26

Question Scheduled task error 2147942401

From what I understand this error means its a bad command but I don't see what. It's a scheduled task with these commands:

Program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Add argument: -executionpolicy bypass -file "C:\Path_to_Script\Script.ps1"

Anyone see what I'm missing or do I have the code wrong?

9 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/Swutter80 Aug 07 '26

No I don't specify the start in path.

The account being used is service account with admin rights on the server and to the target it needs to access in the script.

Script runs when when I just run it normally. Ran it as myself and as the service account.

The script goes through a UNC path and targets files older then a certain date and deletes them.

3

u/Gormless_Shrimp_635 Aug 07 '26

If you create the task to run as a specific user and save it, I'm guessing it runs fine straight after creation.

If you then edit the task (schedule, script argument, etc.) and save it, sometimes it can strip the domain off the specified user without warning, and any subsequent runs fail with errors.

Edit the task and manually re-enter the specified user creds, save, and try run it.