simple restart service script

Welcome Forums General PowerShell Q&A simple restart service script

Viewing 2 reply threads
  • Author
    • #201936
      Topics: 2
      Replies: 0
      Points: 11
      Rank: Member


      I have one service which is running on server 2016 and this service needs to restart everyday in same excat time. To do this I have create basic ps  commands in order to achive mentioned. It is triggered by “task schedule” in Windows. Now problem is with errors which happens when job runs.

      this is error msg:

      “Task Scheduler did not launch task “\start script” because instance “{23c346c4-3c6c-4fa8-8bde-d242d71dbc05}” of the same task is already running.”

      PS  commands are:

      “Stop-Service -Name script-file-service -Force
      Start-Service -Name script-file-service ”

      can you please advise how to solve this?

      Thank you in advance

      ps begginer


    • #201945
      Topics: 4
      Replies: 70
      Points: 192
      Helping Hand
      Rank: Participant

      I don’t think this is a PowerShell issue.  Sounds like your script is not terminating properly.  I found this solution

      On the PowerShell side, you might want to use the Restart-Service command instead of Stop-Service then Start-Service.  Get-Help on Restart-Service for more info.

    • #201966
      Topics: 5
      Replies: 106
      Points: 272
      Helping Hand
      Rank: Contributor

      And always good idea to put exit in the end. That will inform task scheduler which state it has ended. Check also the settings for how long the script can be run untill it is killed.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.