If you are new to Windows administration or to PowerShell, little things like getting a .PS1 script to run in Task Scheduler can be quite frustrating.
As you can see in the screenshot below, it is easy to set a .PS1 file to automatically run:
- Launch Task Scheduler
- Expand Task Scheduler Library
- Right click on the background and select CREATE NEW TASK (or select it from the ACTIONS pane on the right)
- On the GENERAL TAB, enter whatever task name and description you want
- On the GENERAL TAB, you will likely want to click CHANGE USER OR GROUP button (middle right) and have the job run as someone else
- like a service account you created in Active Directory just for this task
- note the you can use the SYSTEM account for many tasks but after you set it to run as SYSTEM you can not longer change the task because you don’t know the password
- On the TRIGGERS tab, click the NEW button and set whatever trigger you want, most commonly a time of day
- On the ACTIONS tab, click NEW and:
- In ACTIONS select START A PROGRAM
- In PROGRAMS SCRIPT type POWERhttps://learn.microsoft.com/en-us/powershell/SHELL (not case sensitive)
- In ADD ARGUMENTS enter the full path to your .PS1 script
- On the CONDITIONS tab, set as you please but often unselecting all options
- On the SETTINGS tab you likely want to configure it to run
- ON DEMAND (so you can right click on it and force it to run anytime you want)
- IF THE TASK FAILS, RESTART EVERY whatever you want
- STOP THE TASK IF IT RUNS LONGER THAN whatever you want
0 Comments