0

I have this Powershell script and I want to schedule it run every 1 minute. So I created the task and schedule it to run every. If Right-Click->Run the scripts runs OK. But when it's scheduled it says that it ran successfully but it's not. I have also checked "Run only when user is logged on" just to make sure that I can see the window when it runs but still nothing. Any ideas?

PS. The arguments line: -ExecutionPolicy Unrestricted -NonInteractive -NoProfile -File C:\dj.ps1

Screenshots: enter image description here enter image description here enter image description here

enter image description here

9
  • Change to run whether user is logged in or not (check the tickbox in the first screen) Dec 16, 2016 at 12:21
  • Already tried that without luck
    – user776720
    Dec 16, 2016 at 12:24
  • 1
    Can you post the script you're running? Dec 16, 2016 at 12:54
  • Unfortunately not because it contains sensitive data. It performs a query on a database and then extracts the result in JSON. Have in mind that if I right-click and click RUN I can see the script executed successfully.
    – user776720
    Dec 16, 2016 at 12:59
  • 3
    Possible that it is being run, throwing an error, and exiting before you can see it.Add first line start-transcript c:\temp\debug.log and last line stop-transcript. Then review the log file.
    – Clayton
    Dec 16, 2016 at 15:49

1 Answer 1

1

I had the same issue (or very similar). I was able to fix it by configuring the scheduled task's action parameters like so:

  • (Program/script:) C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • (Add arguments) -ExecutionPolicy Bypass -File "C:\full\path\to\folder\containing\the\PSscript\script.ps1"
  • (Start in) C:\full\path\to\folder\containing\the\PSscript\

Hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .