Executing powershell scripts via Task Scheduler


  • Hi,

    I have a powershell script that I wrote that when executed from the shell works fine but when executed from task scheduler does not work.

    In my script, an email is sent out based on the results of the execution.  When I run this from the shell, email goes out, when scheduled, no email and there is no indication of errors having occurred anywhere in the system.

    Has anyone run into a similar issue?

    I did change my powershell execution policy to be unrestricted (both in the x86 and x64 consoles).  I am running Windows 2008 R2.

    Thanks - Greg.

    Tuesday, April 10, 2012 7:17 PM


All replies

  • How to Schedule a PowerShell Script   

    Use Scheduled Tasks to Run PowerShell Commands on Windows

    Command Line: powershell -executionpolicy bypass -file script.ps1


    • Edited by Kazun Tuesday, April 10, 2012 7:49 PM
    • Proposed as answer by Bigteddy Tuesday, April 10, 2012 7:55 PM
    Tuesday, April 10, 2012 7:42 PM
  • Powershell script can be run from Schedule task. Just specify Powershell.exe as application and pass .ps1 (powershell file) as argument.

    Secondly, verify following settings for further troubleshoot

    1) Make sure you are using appropriate credential on task schedular. Change User Or Group if require.

    2) Try to run task with "Run with highest privileges" checked

    3) check task history to get more details if task is failing.

    Thanks & Regards
    Bhavik Solanki

    Please click “Mark as Answer” if this post answers your question and click "Vote as Helpful if this Post helps you.

    • Proposed as answer by Bigteddy Tuesday, April 10, 2012 7:53 PM
    Tuesday, April 10, 2012 7:47 PM
  • In my environment, I run a scheduled job calling a powershell script this way which has worked great:

    Under the Actions tab of the scheduled job I have the following information:

    Program/Script: C:\windows\system32\windowspowershell\v1.0\powershell.exe (This is always the same)

    Add Arguments: <path to the powershell script>

    Another thing is to make sure that, if needed, you have Run with highest privileges checked as well.

    Boe Prox

    Please remember to mark the best solution as the answer using Mark as Answer. If you find a solution to be helpful, please use Vote as Helpful.

    Looking for a script? Check out the Script Repository
    Need a script written for you? Submit a request at the Script Request Page

    • Proposed as answer by Bigteddy Tuesday, April 10, 2012 7:52 PM
    Tuesday, April 10, 2012 7:49 PM
  • Hi,

    In addition the above suggestions, please also refer to the below threads:

    Using Task Scheduler for a powershell script on server 2008

     Using Windows Task Scheduler to execute Powershell Script frequently

    Hope this helps.

    Best Regards,

    Yan Li

    Yan Li

    TechNet Community Support

    Wednesday, April 11, 2012 5:43 AM
  • Hi,

    Thanks for everyone's suggestions, going through my script and the above I've narrowed the problem down to the parameters I am passing in.  Some of my parameters have spaces in them and even though they are all enclosed in " ", the task scheduler will only take the first field in the actual parameter.

    It's not really an option for me to change the data to not have a space (as I cannot always guarantee this).


    -MyUserPolicy "This is the name of the policy"

    Anyone have ideas on escaping to get around this?


    Wednesday, April 11, 2012 2:40 PM
  • It can be awkward, difficult, or impossible to pass parameters containing characters that need to be escaped when two or more interfaces must be passed that have different special characters and different escaping methods. My only suggestion would be to experiment.

    Another way to accomplish this would be to schedule a different script that runs the script you want to  run with the parameters you need to have passed to it.

    Al Dunbar

    Wednesday, April 11, 2012 3:22 PM
  • Found the answer to this - enclosing my entire arguments in double quotes and then my parameters in single quotes ensured that the correct values were being passed to my parameters.

    Wednesday, April 11, 2012 3:44 PM
  • Try wrapping the whole thing up in a cmd or batch file.

    Put this in a one line batch file and shedule it

    C:\windows\system32\windowspowershell\v1.0\powershell.exe -executionpolicy bypass -file script.ps1 param param param

    • Edited by OldDog1 Wednesday, April 11, 2012 3:51 PM spelling
    Wednesday, April 11, 2012 3:47 PM
  • Hi Greg,

    ensure that your task runs with the SYSTEM user account.

    Best Regards,


    Wednesday, April 17, 2013 9:15 AM
  • On a slightly related note, make sure that the execution policy is set to allow the script to run, either on the server itself or from the command called to launch the PowerShell script.  You can see your current execution policy setting by running PS:>get-executionpolicy  (if it's restricted it won't run).

    Thursday, May 02, 2013 5:36 PM
  • Very nice! Thanks! I think
    -executionpolicy bypass
    was the key to the kingdom for me!
    Thursday, September 25, 2014 3:45 PM
  • Setting the explicit path to powershell.exe did the trick. However, I'd suggest that you use the environment variable %systemroot% to get to the system root, as not all systems have C:\windows, though most have.

    Same goes for %programfiles%, which indeed is localized, so that does actually change...


    Wednesday, December 03, 2014 12:47 AM
  • I also had issues executing a Powershell script from the task scheduler so I created a batch file to execute the Powershell script and that fixed the issue.

    Batch file contents:

    Powershell.exe -File C:\script.ps1

    • Edited by Johnny4vt Monday, December 15, 2014 9:21 PM Modified to remove -executionpolicy remotesigned for security purposes.
    Monday, December 15, 2014 9:11 PM
  • I also pulled out quite a few hairs getting my powershell script(s) to work.  I finally found that I had to call powershell as Powershell.exe instead of powershell.exe.  Example:

    Scheduled Task > Actions > Action > Start a Program:



    Add arguments (optional):


    I don't have a great explanation for why the "P" in powershell had to be capitalized, but it solved my issue.

    Tuesday, March 31, 2015 7:05 PM
  • I tried everything and spent countless hours only to realize the value of a Capital P in Powershell.exe! Maybe it is a newbie least in my case. 
    Tuesday, October 20, 2015 4:07 PM