How Can I Run a PowerShell Script Automatically Every Day?

0
4
Asked By TechWhiz2023 On

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

Answered By ScriptSavant99 On

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.

Answered By PowerShellPal88 On

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.

Answered By TechTroubleshooter11 On

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.

Answered By SysAdminHero On

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.

Answered By AskMeAnything55 On

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.