gre*_*egg 3 powershell powershell-3.0
寻找与此 cmd 错误检查等效的 PowerShell:
\n\nIF %ERRORLEVEL% NEQ 0
这是我试图编写的 PowerShell 代码:
\n\nWrite-Information "Installing .NET 3 from DVD:"\n$NetFX3_Source = "D:\\Sources\\SxS"\ndism /online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:$NetFX3_Source /NoRestart\nIF (****TheCommandYouTellMe****) {\nWrite-Information "DVD not found, installing from online sources, the Win default method"\nDISM.EXE /Online /Add-Capability /CapabilityName:NetFx3~~~~\nAdd-WindowsCapability \xe2\x80\x93Online -Name NetFx3~~~~\n}\n
Run Code Online (Sandbox Code Playgroud)\n
由于dism.exe
是外部程序,您需要检查$LASTEXITCODE
自动变量:
dism /online /andsoon
if($LASTEXITCODE -ne 0)
{
# Add your capability
}
Run Code Online (Sandbox Code Playgroud)