Powershell script not running when attached to an event and set on schedule

Viewing 5 reply threads
  • Author
    • #565487
      Member Points: 329
      Rank: 2

      I have a powershell script that is supposed to run when a certain event ID is obtained. The script runs fine on its own but as a task schedule it does not. Please help troubleshoot

    • #568058
      Eric Gazrighian
      Member Points: 63
      Rank: 1

      Check with which user account it is scheduled to run. Try with your own admin account.

    • #568063
      Paolo Frigo
      Member Points: 433
      Rank: 2

      From your description seems that your issue is with the task scheduler and powershell.

      Please check:

      • User or Service Account that will be used for running that script.
      • that the action “start a program” contains powershell.exe
      • Pay attention to execution policies, maybe adding “-ExecutionPolicy Bypass” in your case is required on that box. Check with Get-ExecutionPolicy
      •  “add argument” field should contain your script with the absolute path.
      • the flag Run whether user is logged on or not should be checked.

      Last but not least task scheduler expects an exit (int) value for your script or the report of the last execution will be always wrong.

      I also suggest you to add few lines for logging. Just in case you’re using write-host on your script, replace it with Write-OutPut.


    • #579814
      Karim Buzdar
      Member Points: 8,068
      Rank: 3

      Hi PNN,

      Is your issue resolved?


      Thank you,

    • #682865
      Kyle Beckman
      Member Points: 372
      Rank: 2

      I would add one thing to check for anyone else wandering into this thread with a similar issue…  If you’re using certain modules, they can provide a feedback prompt that you’ve already accepted in your account, but that hasn’t been accepted in the account.  When your scheduled task is running as a different account, the script will hang on that prompt and the task will get killed by the Task Scheduler when it exceeds its allotted run time.  These modules usually have a way to accept or provide that feedback in one of the parameters so that you don’t have to use it interactively.

    • #682963
      David Figueroa
      Member Points: 4,448
      Rank: 3

      I would wrap the entire thing with a Start-Transcript to see what is going on, and replace whatever executable with just a Set-Content to validate that it is being triggered properly.

      David F.

Viewing 5 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account