Are you looking for a way to execute PowerShell scripts based on triggers such as time, events, or at startup? This article will demonstrate how to execute PowerShell scripts with the Task Scheduler.
1. Create Your Script
For this article we're going to use a very basic PowerShell script that will ping a local network device. This can be automated in other ways, but the purpose of this article is to demonstrate how to trigger PowerShell scripts.
Here are the contents of my script called ping.ps1
Then right-click the white background and select Create Basic Task. Alternatively, in the menu select Action > Create Basic Task
Next type a name and description for the task as shown below and click Next.
After naming the task, we will select a Trigger for the task. In this case, we'll select When the computer starts. As the description implies, this task will run every time the computer is turned on.
Next up we'll configure the action. This part can be tricky so be sure to double check for typos.
For this task the Action will be to Start a Program. This is what will start PowerShell.
In the Program/script field, type powershell.
In the Add arguments (optional) field, we will need the location of the script and an argument for the Execution Policy depending on how your Execution Policy is currently configured. More on Execution Policies.
For the purposes of this article, paste the text below and be sure to update the location of your script.
-ExecutionPolicy Bypass C:\Windows\Powershell\ping.ps1
Click Next and Finish to save your new task.
3. Test Your Task
Now we will test to make sure our task works. Simply right-click the task, select Run, and your script will execute. If the script runs too fast to visually see it execute, the Last Run Time or History tab can be used to verify successful run time. History is a great place to troubleshoot as well if issues are experienced.
Sheridan's interests are in technology, business, music, and adventures