simple restart service script


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


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.

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.