PowerShell equivalent of cmd “IF %ERRORLEVEL% NEQ 0”

前端 未结 1 963
半阙折子戏
半阙折子戏 2020-12-22 04:32

Looking for the PowerShell equivalent of this cmd error-check:

IF %ERRORLEVEL% NEQ 0

Here is the PowerShell code I am trying to write:



        
相关标签:
1条回答
  • 2020-12-22 04:56

    Since dism.exe is an external program, you'd want to check the $LASTEXITCODE automatic variable:

    dism /online /andsoon
    if($LASTEXITCODE -ne 0)
    {
        # Add your capability
    }
    
    0 讨论(0)
提交回复
热议问题