PSScheduledJob always Running

Mario Neves 1 Reputation point
2021-09-28T05:34:13.727+00:00

Hi,

I have a simple Job Running everyday to Restart the server, but the state is always "Running", is this normal ? Just one is completed.

Id Name PSJobTypeName State HasMoreData Location Command


1 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force
2 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force
3 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force
4 Restart-Server PSScheduledJob Completed False localhost Restart-Computer -force
5 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force
6 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force
7 Restart-Server PSScheduledJob Running False localhost Restart-Computer -force

Thank you,
MN

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,387 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Limitless Technology 39,391 Reputation points
    2021-09-28T15:07:49.237+00:00

    Hi there,

    Yes, it is normal for the Process to run in the task scheduler .


    If the reply is helpful, please Upvote and Accept it as an answer

    0 comments No comments

  2. Mario Neves 1 Reputation point
    2021-09-30T14:52:54.877+00:00

    Hi,

    thank you for your answer, my doubt is the process doesn't finish, it's always in the state of running, only one job in 10 is completed.

    0 comments No comments

  3. Rich Matheisen 45,096 Reputation points
    2021-10-01T20:00:28.483+00:00

    You've shown us the status of the jobs, but not the code that the job runs. Can you post the code?

    Is there anything in the code that would cause the job to not complete?

    0 comments No comments

  4. Mario Neves 1 Reputation point
    2021-10-04T06:11:41.35+00:00

    Hi,

    thank you to take your time :).

    the job cannot be more simple than this ....

    $T = New-JobTrigger -Daily -At 6:01AM

    Register-ScheduledJob -Name Restart-Server -FilePath "C:\restart-vm.ps1" -Trigger $T

    My doubt is also quite simple, should not the job be finished (completed), sometimes the job may have problems, but after being executed should go to the state completed.

    PS: "Restart-vm -force" is the command

    Thank you,
    Mario

    0 comments No comments

  5. Rich Matheisen 45,096 Reputation points
    2021-10-04T15:13:57.66+00:00

    So your assumption is that the Restart-VM always succeeds? The "-Force" parameter just says not to ask for confirmation before restarting. But a "stuck" VM isn't going to (or can't) accept the command at all.

    Can you add a time limit to the scheduled job?

    0 comments No comments