Catch wzzip return codes in PowerShell

314 views Asked by At

I currently have a PowerShell script that zips items that aren't already in a specified folder. I need my script to return wzzip's error codes if one is thrown, so I can handle it in the rest of my script. I've provided a bit of my script below:

foreach ($File in Get-ChildItem $Path\$Item -Recurse | Where {$_.PSIsContainer -ne $true}) {
    WZZIP.EXE $Path\$Item.zip $File.FullName
}
1

There are 1 answers

0
Ansgar Wiechers On BEST ANSWER

PowerShell automatically stores the exit code of external programs in the automatic variable $LASTEXITCODE.

WZZIP.EXE ...
if ($LASTEXITCODE -ne 0) {
    # do stuff here
}