Hi guys, I was trying to create a script for backing up the print environment.
In the script, I call printbrm.exe, which might work flawless, or might return an error code.
I would like to do some action (like sending an email) when an error code appears.
My line in Powershell looks like this:
C:\Windows\System32\spool\tools\printbrm.exe -B -S <myprintserver> -F D:<myprintserver>.export
This line calls the printbrm executable and adds the parameters -B (for backup), -S (for specifying the server) and -F (for specifying the export file).
If the backup works fine, printbrm.exe throws a result in the console “Successfully finished operation”.
If the export file is already existing, printbrm.exe returns “The following error occurred: 0x80070050. The file exists.”
Now, I would like to do an action, if there is any error code.
How can I catch this one? I read about the “$?” variable and “$Lastexitcode”, but they always return 0 or $true respectively.
Thank you in advance!