Force kill a service and restart it with powershell in a batch script

Just replace the TermService and ‘Remote Desktop Services’ with the service name you wish to force kill and restart it.

[shell]
FOR /F “tokens=3” %%A IN (‘sc queryex TermService ^| findstr PID’) DO (SET pid=%%A)

taskkill /F /PID %pid%

sleep 10

powershell -Command “& {Start-Service -displayname ‘Remote Desktop Services’}”
[/shell]

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *