Problem
You are unable to get a Power Shell file to execute using the Task Scheduler
Cause
Two reasons:
- The execution policy needs to be set to Unrestricted
- The command in Task Scheduler needs to adhere to the correct syntax
- You must store the script in a place PowerShell trusts.
Solution
Firstly, store your powershell script in a place PowerShell trusts. To find this, open PowerShell and run:
$env:path
You will note that one of the safe places is “C:WindowsSystem32”.
Next, Set the execution Policy to Unrestricted using PowerShell. Open PowerShell as administrator and run:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Press “A” to accept the changes. If you are using a computer account to run the script, you may need to set the execution policy on the local machine to Unrestricted like this:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine
Create a sheduled task as desired. On the actions tab the script must be run like this:
PowerShell.exe “C:WindowsSystem32MyScript.ps1”
Taking care to wrap the path in double quotes.