Thanks! This solution was the only one that worked for me for scheduling powershell scripts. The solutions with “&’script.ps1′” did not work but yours, “” worked perfectly.
Does anyone know we do this on 2003? It doesn’t appear to work for me there. Is the syntax different? I create the task, run it and get the message “Could not start”
Thanks!
The path and the name of the script can have spaces in it.
If the scheduled task does not give a result, it is likely your powershell execution policy, which prevents the script from running. Type get-executionpolicy or get-executionpolicy -list in a powershell (watch out to take the one you will use – system32 or SysWOW64) to see what it actually is set to. Type set-executionpolicy e.g. set-executionpolicy RemoteSigned.
Hal Rottenberg | 10-Jul-08 at 5:10 pm | Permalink
Gonna include this in the next PowerScripting Podcast. (http://powerscripting.net)
Hal Rottenberg | 10-Jul-08 at 5:15 pm | Permalink
What did you use to make this screencast? Drop me an email if you don’t mind.
Mark | 06-Jan-09 at 5:58 pm | Permalink
Thanks! This solution was the only one that worked for me for scheduling powershell scripts. The solutions with “&’script.ps1′” did not work but yours, “” worked perfectly.
EDF | 25-Aug-09 at 7:42 pm | Permalink
Does anyone know we do this on 2003? It doesn’t appear to work for me there. Is the syntax different? I create the task, run it and get the message “Could not start”
Thanks!
Hethu | 25-Nov-09 at 3:42 am | Permalink
why not simply run powershell.exe
with arguments: -File “”
glnsize | 30-Nov-09 at 11:38 am | Permalink
You could and probably should use the -file switch in lieu of of dot sourcing the script.
~Glenn
Denis Grimard | 19-Jul-10 at 1:24 pm | Permalink
In 2003 or XP use:
C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -File c:\scripts\Scriptname.ps1
all the above on one line and it works like a charm
suckupper | 27-Jul-10 at 4:14 am | Permalink
In Windows Server 2008 R2 use:
program/script: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
add arguments (optional): & ‘\example script.ps1′
The path and the name of the script can have spaces in it.
If the scheduled task does not give a result, it is likely your powershell execution policy, which prevents the script from running. Type get-executionpolicy or get-executionpolicy -list in a powershell (watch out to take the one you will use – system32 or SysWOW64) to see what it actually is set to. Type set-executionpolicy e.g. set-executionpolicy RemoteSigned.