powershell - $lastExitCode not working for 7-Zip update -
what i'm trying databases , part of process zip them they're not in 1 file, smaller file have following code.
# 0 = sunday, 1 = monday, 2 = tuesday, 3 = wednesday, etc $blocation = 'c:\sqlbackups' $7zlocation = 'c:\program files\7-zip\7z.exe' $date = get-date $daynum = [int]$date.dayofweek $month = get-date -format mm $day = (get-date).adddays(0).tostring('dd') $sqlfile = "*_backup_" + $date.year + "_" + $month + "_" + $day + "_*.bak" cd $blocation & $7zlocation d aboch2_sql_backup.zip *.bak & $7zlocation u aboch2_sql_backup.zip *.bak if($lastexitcode -eq 0) { del /q *.bak }
after emptying out .zip file previous runs, update .zip file newly dumped databases , delete databases after .zip updated. issue i'm facing after running .zip file updated new databases. however, $lastexitcode
not working databases added .zip never deleted , end backlog of old databases accumulating.
am missing something, or wrong?
i going guess delete operation failing. question how being called or maybe suppressing error. line has del /q *.bak
when executed should have error along lines of:
remove-item : positional parameter cannot found accepts argument '*.bak'. @ line:1 char:1 + del /q *.bak + ~~~~~~~~~~~~ + categoryinfo : invalidargument: (:) [remove-item], parameterbindingexception + fullyqualifiederrorid : positionalparameternotfound,microsoft.powershell.commands.removeit emcommand
if run command get-alias del
see "del" alias remove-item
cmdlet. perhaps $lastexitcode
logic sound? opt powershell way remove files:
remove-item *.csv -confirm:$false
or if wanted use cmd
cmd.exe /c "del /q *.bak"
Comments
Post a Comment