2017-03-27 12 views
1

大きなスクリプトを使用して、ADEチェックの下に失敗した場合(ADEのインストールが失敗した)、スクリプトステータス全体が変更される失敗する。誰でも条件を追加するためにここで私を助けてもらえますか?特定のチェックがスクリプトから失敗した場合のpowershellスクリプトの失敗

if (($ImageName -like "*devel*") -or ($ImageName -like "*hosted*")) 
     { 
      #$ADE1 = Invoke-Expression ('C:\ade\bin\ade.exe | select-string -pattern "begintrans"') | out-string ; $ADE = $ADE1.trim().split("")[1] 
      Invoke-Expression ('C:\ade\bin\ade.exe | select-string -pattern "begintrans"') > C:\Temp\ade_check.txt 
      #Invoke-Command -ScriptBlock { & 'C:\ade\bin\ade.exe' | Select-String -Pattern 'begintrans' > C:\Temp\ade_check.txt } -Credential $Credentials -ComputerName $env:COMPUTERNAME 
      $ADE1 = Get-Content C:\Temp\ade_check.txt | Select-String "begintrans" | out-string ; $ADE = $ADE1.trim().split(" ")[1] 


      if ($ADE -eq "begintrans") 
      { 
      $ADE = "ADE Installation Success" 


      Add-Content $report "<tr>" 
       Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
      Add-Content $report "<td bgcolor= 'Aquamarine' height='30' align=left><B>$ADE</B></td>" 
      Add-Content $report "</tr>" 

    echo "ADE = ADE Installation Success" 

      } 

      if ($ADE -eq $null){ 
      $ADE = "ADE Installation Failed" 


      Add-Content $report "<tr>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
      Add-Content $report "<td bgcolor= 'red' height='30' align=left><B>$ADE</B></td>" 
      Add-Content $report "</tr>" 

    echo "ADE = ADE Installation Failed" 
      } 

     } 
     else 
      { 
      if (($ImageName -like "*simple*") -or ($ImageName -like "*BareOS*")){ 

      $ADE = "BareOS, ADE Not Installed" 


      Add-Content $report "<tr>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=center><B>17</B></td>" 
      Add-Content $report "<td bgcolor= 'White' height='30' align=left><B>ADE</B></td>" 
      Add-Content $report "<td bgcolor= 'Yellow' height='30' align=left><B>$ADE</B></td>" 
      Add-Content $report "</tr>" 

    echo "ADE = BareOS, ADE Not Installed" 
      } 
      } 

答えて

0

あなたはそのような方法でスクリプトを失敗させるべきではなく、それを捕まえるためにtry/catchブロックを使うべきです。それでも一瞬スクリプトを失敗したい場合でも、あなたはスクリプトを失敗する強制的に終了コマンドを使用することができ、を「ADEのインストールに失敗しました」。これに代えて

if ($ADE -eq $null){ 
      $ADE = "ADE Installation Failed" 
exit 1 

      Add-Content $report "<tr>" 

if ($ADE -eq $null){ 
      $ADE = "ADE Installation Failed" 


      Add-Content $report "<tr>" 

これを行います

関連する問題