1

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

IF %ERRORLEVEL% NEQ 0

Here is the PowerShell code I am trying to write:

Write-Information "Installing .NET 3 from DVD:"
$NetFX3_Source = "D:\Sources\SxS"
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~~~~
}
Tony Hinkle
  • 4,636
  • 7
  • 22
  • 34
gregg
  • 956
  • 1
  • 10
  • 23

1 Answers1

4

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
}
Mathias R. Jessen
  • 135,435
  • 9
  • 130
  • 184