# simple restart service script

**URL:** <https://forums.powershell.org/t/simple-restart-service-script/13764>\
**Category:** PowerShell Help\
**Created:** [February 5, 2020, 9:04am UTC](https://forums.powershell.org/t/simple-restart-service-script/13764 "2020-02-05T09:04:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jungleroot](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@jungleroot](https://forums.powershell.org/u/jungleroot)\
**Post date:** [February 5, 2020, 9:04am UTC](https://forums.powershell.org/t/simple-restart-service-script/13764/1 "2020-02-05T09:04:02Z")

</div>

Hello

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

🙂

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [February 5, 2020, 9:32am UTC](https://forums.powershell.org/t/simple-restart-service-script/13764/2 "2020-02-05T09:32:51Z")

</div>

I don’t think this is a PowerShell issue. Sounds like your script is not terminating properly. I found this solution [https://superuser.com/questions/1106016/task-launch-failed-instance-already-running](https://superuser.com/questions/1106016/task-launch-failed-instance-already-running)

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.

---

<div class="post-metadata">

**Author:** ![aapeli-hietikko](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@aapeli-hietikko](https://forums.powershell.org/u/aapeli-hietikko)\
**Post date:** [February 5, 2020, 10:12am UTC](https://forums.powershell.org/t/simple-restart-service-script/13764/3 "2020-02-05T10:12:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/simple-restart-service-script/13764/4 "2024-05-16T20:31:03Z")

</div>

Closed on May 16, 2024, 8:31pm UTC


