Link to home
Create AccountLog in
Avatar of wicked212
wicked212

asked on

Service Stop Validation

Hi,
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"
}
ASKER CERTIFIED SOLUTION
Avatar of mouseware
mouseware

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of wicked212
wicked212

ASKER

ty mouseware!