try/catch
in PowerShell doesn't work with exe.
After myservice.exe
calls you need to check the automatic variable $LastExitCode
.
Try something like this:
$out = & $cmd start
if ($LastExitCode -ne 0) # if exe returns 0 on success, if not change the condition accordingly
{
"ERROR: $out"
return # to exit script or do something else.
}