Josh Verdin
Josh Verdin

Reputation: 1

GPG Decyrption from Powershell

I am trying to decrypt files with GPG from powershell. It has been painful... my command works fine interactively or from the POWERSHELL ISE in Debug Mode. However as soon as I run the PS Script from Task Scheduler it runs and gets to the part of the script where I call GPG.exe and nothing happens. I see GPG fire up in the process but nothing happens. It should Decrypt the file and output as a text file.

 #Call gpg4win to decrypt files in "E:\BannerAWS\SAPConcur\Production\"

$Files = Get-ChildItem -Path "E:\BannerAWS\SAPConcur\production" -Filter "*.pgp"
Write-Log "Beginning Decrpytion on $Files.Count"


if ($Files.Count -ge 1)
{
    ForEach ($file in $Files) 
    {
        #C:\Scripts\DecryptConcur.bat
        $OutPut = $file.fullname.SubString(0, $File.FullName.length -4)
        Copy-Item -Path $file.fullname -Destination $BackUpGPG 
        & "C:\Program Files (x86)\GnuPG\bin\gpg.exe" -v --batch --pinentry-mode=loopback --passphrase "$PassPhrase" -d -o $OutPut $file.FullName
         Start-Sleep -seconds 1
         

             
         if (Test-Path $OutPut) 
        {
            Write-Log "Deleting File $File" 
            Remove-Item $File.fullname
            Write-Log "Copying Decrypted File to Archive."  
            Copy-Item -Path $OutPut -Destination "E:\BannerAWS\SAPConcur\archiveproductiontest\"
        }
        Else
        {   
            if(-Not (Test-Path $OutPut))
            {Write-Log "Decrypted File was never created."}
        }
    }
    Write-Log "Calling Load Script"
    #C:\scripts\loadfzrsaetproduction.bat
    Write-Log "Load Script ran and complete see log at c:\scripts\fzrsaetlog.txt"
}
Else
{
    Write-Log "No Files to Decrypt Found"
} 


I suspect that its having a problem with permissions but not sure exactly. I know the file never gets decrypted. I looked into the start-process to use the "-verb RunAS" but cannot figure out how to convert this arguement list that would follow the exe.

Upvotes: 0

Views: 82

Answers (0)

Related Questions