1

Windows Server 2008 R2 の 64 ビット マシンで、次のコードを実行しています。

$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
}
}

これは、すべてのコンピューター ph1、ph2、および ph3 で再現できます。ただし、他のコードを使用すると、WAS を開始でき、それぞれのステータスを確認できます。

また、次の点にも注意してください。

  1. 他のすべてのサービスを停止できますか? WAS のパスがこのようになっていることと関係がありますか? C:\Windows\system32\svchost.exe -k iissvcs
  2. 意図的に WMI を使用しています。

ここで何が起こっているのですか?

ティア

4

1 に答える 1

0

問題は、最初に停止する必要がある WAS に依存する複数のサービスがあることです。StopService ()メソッドには、依存サービスを停止するためのオーバーロードがありません。これで問題が解決しない場合は、StopService からの応答コードを確認して、上記のリンクの問題を特定してください。

コード 3 を「サービスが存在しません」として処理しているようです。ドキュメントは、このコードが実際には「実行中の他のサービスがサービスに依存しているため、サービスを停止できない」ことを意味していることを示しています。

この機能が完全に PowerShell に組み込まれているのに、WMI を使用することに決めた理由がわからない

Stop-Service WAS -Force

WAS サービスのプロパティ

于 2015-07-17T23:46:55.920 に答える