I was able to add the function and run it, however, it only encrypted a single file out of 3 when I expected it to do the entire folder. From reading the function it looks like it should do the entire folder. Below is the function and my script.
Add-Encryption Function
[CmdletBinding()]
[OutputType([System.IO.FileInfo])]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path -Path $_ -PathType Container})]
[string]$FolderPath,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Password,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$GpgPath = 'C:\Program Files (x86)\GnuPG\bin\gpg.exe'
)
process {
try
{
Get-ChildItem -Path $FolderPath | foreach {
Write-Verbose -Message "Encrypting [$($_.FullName)]"
Start-Process -FilePath $GpgPath -ArgumentList "--batch --passphrase $Password -c $($_.FullName)" -Wait -NoNewWindow
}
Get-ChildItem -Path $FolderPath -Filter '*.gpg'
}
catch
{
Write-Error $_.Exception.Message
}
}
Calling the Function and Output
$EncryptionTarget = "C:\Users\myself\Documents\Files-ToEncrypt"
$Passphrase = "Password1"
Add-Encryption $EncryptionTarget -Password $Passphrase
Output
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10/24/2019 4:43 PM 79 test.docx.gpg
I expected all 3 test documents to come out.
I have 3 documents within
$EncryptionTarget = "C:\Users\myself\Documents\Files-ToEncrypt"
I only get the 1st document encrypted.