PowerShell相当于cmd";if%ERRORLEVEL%NEQ 0&QOOT; [英] PowerShell equivalent of cmd "IF %ERRORLEVEL% NEQ 0"
本文介绍了PowerShell相当于cmd";if%ERRORLEVEL%NEQ 0&QOOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在查找此cmd错误的PowerShell等价物-检查:
IF %ERRORLEVEL% NEQ 0
以下是我尝试编写的PowerShell代码:
Write-Information "Installing .NET 3 from DVD:"
$NetFX3_Source = "D:SourcesSxS"
dism /online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$NetFX3_Source /NoRestart
IF (****TheCommandYouTellMe****) {
Write-Information "DVD not found, installing from online sources, the Win default method"
DISM.EXE /Online /Add-Capability /CapabilityName:NetFx3~~~~
Add-WindowsCapability –Online -Name NetFx3~~~~
}
推荐答案
由于dism.exe
是外部程序,您需要检查$LASTEXITCODE
自动变量:
dism /online /andsoon
if($LASTEXITCODE -ne 0)
{
# Add your capability
}
这篇关于PowerShell相当于cmd";if%ERRORLEVEL%NEQ 0&QOOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文