Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I schedule a Powershell script to run every day at 3am in Windows 8?

share|improve this question
1  
What have you tried so far? Did you attempt to use Task Scheduler? Use powershell /? to know how to run a PS1 script from the command-line. –  Karan Dec 27 '12 at 22:30
    
I tried using Task Scheduler to run the script, but when I try to test it by running it from the Scheduler, its status changes to Running and never finishes. Note that I tested the script and it successfully runs and exits if you right click it run it with Powershell. –  Wesley Tansey Dec 27 '12 at 22:36
    
You should have mentioned this in the original question, else as you can see below people will just waste their time teaching you how to create a scheduled task. Did you try setting the task to run as admin/with highest privileges? –  Karan Dec 27 '12 at 22:45
    
Yes, I tried that as well. It is set to run with highest privileges. –  Wesley Tansey Dec 27 '12 at 22:48
1  
Why not set a trigger a few mins. from now and simply test? –  Karan Dec 27 '12 at 23:37
show 12 more comments

3 Answers

up vote 1 down vote accepted

EDIT: This is a proof of concept that worked for me.

  1. open a new textfile and type in
    write-Host 'Hello World'
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

  2. save it as hello.ps1 on your desktop

  3. open the 32-bit version of powershell.exe with elevated rights
    (right click + open as administrator)
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

  4. make sure, that you didn't use the x64 version until you want to
    C:\Windows\syswow64\Windowspowershell\v1.0\powershell.exe

  5. On my Windows 7 the "Windows PowerShell (x86)" startmenu shortcut points to the x64 version! These versions use seperate policy settings. It took me a while to figure that out :)

  6. Type in the following to allow powershell scripts and confirm it with Y
    Set-ExecutionPolicy Unrestricted

  7. That setting is stored permanently. Do a reboot just to check that.

  8. check the powershell policy and confirm that it is still unrestricted with
    get-ExecutionPolicy

  9. open schedule task window

  10. make a scheduled task which points at the x86 version
    C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe

  11. Type in the following for the optional parameter:
    c:\users\YOURUSERNAME\desktop\hello.ps1

  12. Execute your task manually through a right-click in your schedule task window

  13. Wonder why it says "running"

  14. Hit F5 to refresh. You will notice that the "still running"-status disappears.

  15. Be happy (after 1 hour :p)

share|improve this answer
    
That does not work. Please see my comment in the original post. –  Wesley Tansey Dec 27 '12 at 22:36
    
What was the exact syntax you used in your task scheduler? –  nixda Dec 27 '12 at 23:08
    
I tried it the way you suggested in your edit. It still just changes the status to Running and never finishes. –  Wesley Tansey Dec 27 '12 at 23:17
    
Please see my full edit. There has to be a normal way. –  nixda Dec 28 '12 at 1:04
    
Regarding step 6, it should probably say "confirm it with Y" (instead of J). I realise it's J for you because your Windows display language is set to German, but SU normally assumes English localisation, unless specified otherwise. –  Indrek Jan 2 '13 at 23:56
show 1 more comment

run 'taskschd.msc', navigate to Powershell and create the job/schedule.

Reference

share|improve this answer
add comment

It took me a while to get my Scheduled PowerShell task to work.

Here are a few tactics that helped me.

a) Get a simple PowerShell script working.
b) Understand all the various Task Manager tabs, including the conditions and actions (I think you have done this already)
c) Watch the path to the various files.


My killer problem was not realising PowerShell was the program and the script was merely an argument.

Another minor help was introducing -ExecutionPolicy Bypass before the file name thus:
-ExecutionPolicy Bypass -File "D:\PShell\Process Task.ps1"

Finally, I am never sure about the SuperUser etiquette, but this is my page on the subject of Scheduling PowerShell.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.