Start Service on a Remote server

Services are mostly to go halt time to time which makes some function or application to cause issue or not start and when you know it is most likely by a service is stopped the below script can you help sort it.

$statusofthePES = (Get-Service -ComputerName "server/machine name" -Name "servicename")

if ($statusofthePES.Status -eq "Stopped")
{
    "PES Service is stopped!!"
    Get-Service -ComputerName "Server/machine name" -Name "servicename"| Start-Service
    "Started Now!!"
}elseif($statusofthePES.Status -eq "Running"){
    "PES Service is Running!!"
    Get-Service -ComputerName "server/machine name" -Name "servicename"| Stop-Service
    "Stopped Now!!"
}

Published by iamfazul

Author of the site

Leave a comment