PowerShell scripts reduce the effort in running repetitive tasks. If you frequently execute scripts at pre-defined times or specified time intervals, you may want an efficient way of not having to execute scripts repeatedly. In this post, we will guide you on how to schedule PowerShell script to run periodically on Windows 11/10 using Task Scheduler.
Schedule PowerShell script using Task Scheduler
It’s assumed you have already created a PowerShell script. To schedule PowerShell script using Task Scheduler, do the following:
- Press Windows key + R to invoke the Run dialog.
- In the Run dialog, type taskschd.msc
- Press CTRL+SHIFT+ENTER key combo to open Task Scheduler in admin mode.
- On the left pane, right-click Task Scheduler Library > Create Task.
- In General tab, you can set scheduler name and description about the task like for what purpose the task has created.
- Switch to the Trigger tab and click the New button. Here, you can set conditions that trigger a task.
- Then open Actions tab and click the New button.
In the Action drop-down, Start a program is set by default. You can change it if required.
Using Browse, select program/script field. To schedule a script, we need to select powershell.exe. You can find powershell.exe in your system32\WindowsPowerShell\v1.0 folder.
In Add arguments, -File parameter is the default one so simply specify the script path. Assume you have created a PowerShell script and saved it to your desktop.
C:\Users\<username>\Desktop\TWC_script.ps1
If the path contains any blank space, it should be enclosed with quotes.
- Once configured, you can specify conditions to determine whether the task should run. The task will not run if any condition specified here is not true.
- On the Settings tab, you can set additional advanced settings to control the task execution.
- Finally, click OK to create a scheduled script.
- Click OK again. You can now exit Task Scheduler.
Read: PowerShell script does not run as Scheduled Task, 0xFFFD0000 error
The scheduled script will run as expected, according to your schedule without any issues. If you want to check script execution, you can click Run by right-clicking the task name.
This is how you can make a PowerShell script run as a scheduled task using Task Scheduler.
How do I schedule a PowerShell script as administrator?
When setting up the task using the Task scheduler, make sure to select the checkbox that allows you to run as administrator. It will use the system administrator account to execute the task in the background, or you can select your account to be used if it’s an administrator account. If not the task will still run, but you will get the UAC prompt.
How do I trigger a PowerShell script remotely?
If you have the right set of permission to access the computer, you can use the Invoke-Command cmdlet with the FilePath parameter to run the script located on that computer. Once you execute the script, you should be able to see the results on the prompt. The options include the computer name and file path of the script.