Sometimes, funky things can happen if all the code isn’t formatted as code. Much appreciated!
It’s not working because you’re formatting the output. Don’t use Format-Table when trying to use it later. Only use Format commands to make it easier to read when viewing the output.
I’d personally also not use ieq unless you really care about casing.
if ($status -eq 'Stopped') {
# start a service
}
Note on the first command I modified it to ‘ExpandProperty’ so you just get the value of Status (no ‘header’), so that way, $status will be just a string.
Looks like your solution works, I was wondering that my code was leaving some extra things in the $status. I was looking for how to get just the result without heading and blank lines,