powershell command to terminate/cancel a script -


is there powershell command available terminate powershell script? have used exit 1, doesn't me. have tried throw gave error. script have tried. want script stop when service status stopped.

$emagent1 = get-wmiobject win32_service | where-object {($_.name -eq 'oim12cagent') -or ($_.name -eq 'oimagent12c2agent') -or ($_.name -eq 'oimagent10gagent') -or ($_.name -eq 'gfarmem10gagent') -or ($_.name -eq 'gfarmem11gagent')} | format-list name | out-string  $agentname1 = $emagent.split(":")[1].trim()  $emstatus1 = get-wmiobject win32_service | where-object {$_.name -eq $agentname} | format-list state | out-string $agentstatus1 = $emstatus.split(":")[1].trim()  if ($agentname1 -eq $null) {     $agentname1 = "unavailable" } else {     $agentname1 = "$agentname1" } if ($agentstatus1 -eq "stopped") {     exit 1 } else  {  }    

use get-service instead since it's faster , easier use.

it's more advisable search desired services begin with, rather getting services , discarding every mismatch later. way don't need handle empty list of services because it's filled right start anyway.

your desired script may this:

$agentlist='oim12cagent','oimagent12c2agent','oimagent10gagent','gfarmem10gagent','gfarmem11gagent'  foreach ($agentservice in $agentlist) {     if ((get-service $agentservice -erroraction silentlycontinue).status -like '*stopped*') {         break         } else {             write-host "do stuff"             }     } 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -