Problem Getting a Powershell Script to Run in Task Scheduler


  1. Posts : 8
    Windows 10
       #1

    Problem Getting a Powershell Script to Run in Task Scheduler


    Hope I'm in the right place!

    I am trying to get a Powershell script to run daily in the task scheduler. It basically purges a folder on one of my drives:

    Get-ChildItem –Path “D:\Dropbox\Quicken\Backup” –Recurse | Where-Object CreationTime –lt (Get-Date).AddDays(-10) | Remove-ItI

    I can run it from a CMD prompt and I set it up in the task scheduler and it seemed to run one time on schedule and then hasn't run since that initial time. I have tried to run it manually from the task scheduler but it gets and error "Task Start Failed."

    I have attached copies of the properties tabs and the main view of the task scheduler with the History showing. Any ideas? I didn't find a tutorial, but I'm sure there is something on the website!

    Cordially,

    Al Guden

    TS-TaskView.pdf
    PROPERTIES-Settings.pdf
    PROPERTIES-Actions.pdf
    PROPERTIES-Triggers.pdf
    PROPERTIES-General.pdf
    PROPERTIES-History.pdf
    PROPERTIES-Conditions.pdf
      My Computer


  2. Posts : 42,737
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, I think you need to create a powershell script file and specify that as your action, not the specific powershell command.

    See this for an extended example, and another below:
    Weekend Scripter: Use the Windows Task Scheduler to Run a Windows PowerShell Script Hey, Scripting Guy! Blog

    https://community.spiceworks.com/how...task-scheduler
      My Computers


  3. Posts : 8
    Windows 10
    Thread Starter
       #3

    Thank you for the help. The 2nd article had the little nugget I needed. -ExecutionPolicy Bypass before the PS1 file did the trick. I started using a PS1 file but couldn't get past the errors with scripts being prohibited. This did the trick. It runs manually. Now we will see if it runs on schedule.

    Thanks again.

    Al
      My Computer


  4. Posts : 42,737
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    Glad it helped- the answer's often 'out there'...
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 07:20.
Find Us




Windows 10 Forums