windows - IIIS WAS process cannot be stopped via Powershell -


on windows server 2008 r2, 64 bit-machine running following code:

$global:arrserver = @("ph1", "ph2", "ph3")  $global:arrdienste = @("w3svc", "was", "iisadmin")  $global:strpfad = "d:\waslogs\" $global:strlogtime = get-date -format "yyyy-mm-dd--hh-mm-ss"     $global:strlogdatei = $global:strpfad + "wartung--" + $global:strlogtime + ".log"       log_abfrage_und_generierung  dienste_stop  function dienste_stop {   echo "stop of services successful?"  | out-file $global:strlogdatei -append -force    foreach($strserver in $global:arrserver)   {     $strinterim2 = $strserver + " (" + $global:appservernamen + ")"     echo  "       " $strinterim2 | out-file $global:strlogdatei -append -force      foreach($strdienst in $global:arrdienste)     {         $objwmiservice = get-wmiobject -class "win32_service" -computer $strserver -filter "name = '$strdienst'"          if( $objwmiservice.state )                     {           $rtnwert = $objwmiservice.stopservice()           switch ($rtnwert.returnvalue)             {                0 { echo "$strdienst stopped!" | out-file $global:strlogdatei -append -force }                2 { echo "$strdienst throws: 'access denied!'" | out-file $global:strlogdatei -append -force }                3 { echo "service $strdienst not existing on $strserver!" | out-file $global:strlogdatei -append -force }                5 { echo "$strdienst stopped!" | out-file $global:strlogdatei -append -force }                default { echo "$strdienst service reports error $($rtnwert.returnvalue)" | out-file $global:strlogdatei -append -force }             }         }         else         {             echo "service $strdienst not existing on $strserver!" | out-file $global:strlogdatei -append -force          }     }  } }  function log_abfrage_und_generierung {     if([io.directory]::exists($global:strpfad)) {     echo "nothing happening here." }  else {     new-item -itemtype directory -path $global:strpfad } } 

this can reproduced on computers ph1, ph2 , ph3. other code, can started, respectively status can seen.

also note:

  1. all other services can stopped? has fact path this? c:\windows\system32\svchost.exe -k iissvcs
  2. i use wmi on purpose.

what going on here?

tia

the problem there multiple services depend on need stopped first. stopservice() method not have overload stop dependent services. if doesn't solve issue check response code stopservice determine problem in link above.

it looks handling code 3 'service not exist'. docs show code means 'the service cannot stopped because other services running dependent on it.'

not sure why you're determined use wmi when capability baked powershell

stop-service -force 

was service properties


Comments