Check Windows service status before nssm STOP (#28379)

* Check Windows service status before nssm STOP

Add a condition on calling nssm STOP inside Nssm-Remove, to check whether or not a service has already been stopped. Currently nssm throws an exception:

```
failed: [...] (item=...) => {"changed": false, "failed": true, "item": "...", "msg": "an exception occurred when invoking NSSM: serviceName: STOP: The service has not been started."}
failed: [...] (item=...) => {"changed": false, "failed": true, "item": "...", "msg": "an exception occurred when invoking NSSM: serviceName: The service has not been started."}
```

Behaviour after change:

```
ok: [...] => (item=...)
ok: [...] => (item=...)
```

* Added named parameter to new Get-Service cmdlet
pull/28601/head
Kira Rose 7 years ago committed by Jordan Borean
parent e7a525bd4a
commit 46cd8ba7cd

@ -96,9 +96,10 @@ Function Nssm-Remove
if (Service-Exists -name $name)
{
if ((Get-Service -Name $name).Status -ne "Stopped") {
$cmd = "stop ""$name"""
$results = Nssm-Invoke $cmd
}
$cmd = "remove ""$name"" confirm"
$results = Nssm-Invoke $cmd

Loading…
Cancel
Save