I am having strange error with my PowerShell script. The first time I run the script shown below I get the following error (in both VSCode and PowerShell directly): Failed to decrypt X:name_of_encrypted_file
SCRIPT snippet:
Get-ChildItem -Path $encryptedFilesPath -Filter "r$region*.gpg" | ForEach-Object {
$encryptedFile = $_.FullName
$decryptedFile = Join-Path -Path $decryptedFilesPath -ChildPath ($_.BaseName -replace '\.gpg
The $passphraseFile has the password enclosed as ‘password$’. I do this because there are special characters in the password.
When I go directly into PowerShell and run the gpg command using the password option instead of the password file with the parameter ‘password$’ (which matches the $passphraseFile), and supplying the name of one of the encrypted files along with the decrypted file name, PowerShell decrypts the file.
I can then run the PowerShell script successfully in VSCode (I am using VSCode until the program behaves properly regularly).
Another development is that when I call the gpg decryption code in VSCode above for two sets of files the first set of files work, but the second set of files gets the “Failed to decrypt X:name_of_encrypted_file error.”
Please note I have tried running the full PowerShell script in PowerShell and get the decrypt error.
Any suggestions what I am doing wrong or why I am getting this behavior?
Thanks, David