EvotecIT / PSPGP

PSPGP is a PowerShell module that provides PGP functionality in PowerShell. It allows encrypting and decrypting files/folders and strings using PGP.
MIT License
59 stars 22 forks source link

How to Handle errors #18

Closed CFGTechAdmin closed 3 months ago

CFGTechAdmin commented 4 months ago

Hi There, I'm using your module within a Powershell script, on of the steps in the script decrypts a file with your module. If I use the right key the file is decrypted ok and creates the file (i.e. file.txt), however, if I use the wrong key, the module does not decrypt the file but it still creates an empty output file (i.e. empty file.txt). To validate success of the decryption I'm validating that the decrypted file has been created. Is there a way I can ask the module not to crete the empty file when it fails to decrypt the file?

Thanks for this module and your help with this issue!

PrzemyslawKlys commented 4 months ago

Does it show a warning when you use it when the empty file happens? What happens if you use -ErrorAction Stop ?

mario-velazquez commented 3 months ago

I cannot find the option to use -ErrorAction

PrzemyslawKlys commented 3 months ago

JUst type it. DoWhatever -ErrorAction Stop -> it will workYou can than do try/catch on it and process any error