Service Stop Validation
Posted on 2013-05-16
I am attempting to stop a remote service (which works great) but struggling to validate that the service has been stopped. Basically, if determined/verified to be stopped, would like to continue the script. If not stopped, then it is likely hung, and I would like to abort and LogWrite that the service was not stopped. Please advise.
$Servers = Get-content "C:\path\servers.txt
foreach ($Server in $Servers)
LogWrite "Issuing remote service stop command to $Server"
#Command to stop service
(Get-WmiObject Win32_Service -computername $Server -Filter "Name='Service_Name'").StopService()
LogWrite "Service stopped on $Server"