2015-07-17 4 views
1

Sur Windows Server 2008 R2, 64-bit machine Je courais le code suivant:IIIS processus WAS ne peut pas être arrêté par Powershell

$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 the 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 is not existing on $strServer!" | Out-File $global:strLogDatei -Append -Force } 
       5 { echo "$strDienst already 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 is 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 
} 
} 

Cela peut être reproduit sur tous PH1 ordinateurs, PH2 et PH3. Cependant avec un autre code, WAS peut être démarré, respectivement le statut peut être vu.

également à noter:

  1. Tous les autres services peuvent être arrêtés? Est-ce que cela a à voir avec le fait que le chemin pour le WAS est comme ça? C: \ Windows \ system32 \ svchost.exe -k iissvcs
  2. J'utilise WMI à dessein.

Que se passe-t-il ici?

Tia

Répondre

0

Le problème pourrait être qu'il ya plusieurs services qui dépendent de WAS qui doivent d'abord être arrêtée. La méthode StopService() n'a pas de surcharge pour arrêter les services dépendants. Si cela ne résout pas le problème, vérifiez le code de réponse de StopService pour déterminer le problème dans le lien ci-dessus.

Il semblerait que vous manipuliez le code 3 car «le service n'existe pas». Les docs montrent que ce code signifie en fait 'Le service ne peut pas être arrêté parce que les autres services en cours d'exécution en dépendent.'

Je ne sais pas pourquoi vous êtes déterminé à utiliser WMI lorsque cette capacité est entièrement cuit dans powershell

Stop-Service WAS -Force 

WAS Service Properties