KB10108 - PS: Create a scheduled task to run a PowerShell script
- Create a task
- Run powershell.exe in the task
- assign a commandline to powershell.exe
This article assumes, that the user has administrative rights on the target server. Also the right "logon as a batch job" is required - The task will add this right if required and if this right is not controlled with GPO or otherwise.
Step by step
- Open "Task Scheduler" console.
- Run "Create a task..."
- General Tab:
(1) Add a Name for you task.
(2) Add the user, that is going to run the task later on.
(3) Switch this box to "Run whether use is logged on or not" to allow task execution without a logged on user.
(4) Enable this box only, if administrative rights are required to execute the script.
- Triggers Tab:
(2) Create a new trigger to run the task on time (or whatever is possible...).
(3) Change the schedule for your script execution.
- Actions Tab:
(2) Create a new action
(3) Bowse for "powershell.exe" (eg.: "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
(4) Add the commandline:
- -noprofile (means no windows user profile will be loaded)
- -executionpolicy bypass (PowerShell execution policy will be ignored to run a unsigned script for example)
- -file "C:/Script/MyPS.ps1" (Path + FileName of you powershell script)
(5) Foldername in which to execute the script (eg.: This should be the script path)
- Save the task by clicking on "OK".
- Now you have to provide the username and password for the account that is going to execute the task.