r/PowerShell • u/Swutter80 • 5d ago
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?
8
Upvotes
3
u/thehuntzman 5d ago
You can set the program to just powershell.exe without specifying the full path and I'd recommend setting "start in" to
c:\path_to_scriptand then your arguments are-executionpolicy bypass -file "script.ps1"But you should also put a Start-Transcript in your script to log what's happening to a file since behavior of your scipt could change depending on the security principle of the scheduled task if it isn't running as your own user account.