I've created a PowerShell script that collects details like the serial numbers, models, and manufacturers of my computer and monitors. It generates a JSON file that I want to save on a server. However, I'm running into an issue: when I try to run this script through Task Scheduler, it fails with a 0x1 error. The script runs fine with admin privileges when executed locally, but it just won't work when automated through Task Scheduler. I'm looking for alternative methods to run this script automatically at 10:00 AM every day. Does anyone have suggestions or insights on how to make this work? I've read a lot of guides on best practices for Task Scheduler, but I still can't get it functioning as intended.
5 Answers
To get your script running in Task Scheduler, make sure to set the Program to 'powershell' and specify the arguments like this: '-executionpolicy bypass -file "pathToPs1File"'. Also, ensure you're using an account with the necessary permissions to execute the script.
If your script is a .ps1 file, have you tried creating a .cmd file that calls the .ps1? Sometimes running it from a batch file can help resolve the issues you’re having with Task Scheduler.
You could set up a while loop in a separate script to keep your computer active, clicking at some coordinates until it’s 10:00 AM, then execute your main task. It’s a bit of a hack, but it might work until you find a proper solution.
Check how you’re deploying this script. Are you doing it as a remediation script or packaging it as a Win32 app? Make sure your script is saved as UTF8 without BOM; that can cause issues.
Are you ensuring that you have the correct PowerShell path set in the Task Scheduler action? Running it directly from a .ps1 could be causing the issue if the path isn't set correctly.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String