If I running this function (with out try..catch):
executezipFullBackup -PathFileLocation "Z:\" -PathSaveBackup "E:\" -NameOfBackup "MyNASStorage"
PoweShell give me this error:
sz :
At C:\PowerShellF\zipFunction.ps1:6 char:9
+ sz a -t7z "$PathSaveBackup\$NameOfBackup" "$PathFileLocation" #backup
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
ERROR:
Duplicate filename on disk:
BackupTest\private\103.tmp\usr\bin\mail
BackupTest\private\103.tmp\usr\bin\Mail
And that error is OK for me, because I know what is wrong on this step.
But my problem is, if I put this script in try..catch, I dont get this error.
Example:
$ErrorActionPreference = "Stop"; #this is for Try Catch
try {
zipFullBackup -PathFileLocation "$PathFileLocation" -PathSaveBackup "$PathSaveBackup" -NameOfBackup "$NameOfBackup"
} catch {
$MyError = ($Error[0] | Out-String);
Write-Host "$MyError"
}
I get error like this:
sz :
At C:\PowerShellF\zipFunction.ps1:6 char:9
+ sz a -t7z "$PathSaveBackup\$NameOfBackup" "$PathFileLocation" #backup
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
This error is not enough for me, because I don't see ERROR! I don't see this:
ERROR: Duplicate filename on disk: BackupTest\private\103.tmp\usr\bin\mail BackupTest\private\103.tmp\usr\bin\Mail
How can I get try..catch to display this error?