首页 > 解决方案 > gpg解密和邮件通知

问题描述

我遇到的两个问题是,

  1. 它完成了这项工作,但引发了如下所示的错误。

  2. 通知不会触发,根本不满足条件。

gpg2.exe : gpg: 使用 2048 位 RSA 密钥加密,ID D9A0AD5F,创建
2017-07-04
在 C:\Scripts\FinanceGPGDecryptor.ps1:24 char:5
+ & <<<< $gpg_prog --batch --yes --passphrase "$gpg_p" -r "$gpg_r" -o "$out_file" -d "$in_file"
    + CategoryInfo : NotSpecified: (gpg: encrypted ...ated 2017-07-04:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

      “key_id>”
# Variables
$gpg_prog = "C:\Program Files (x86)\GNU\GnuPG\pub\gpg2.exe"
$sFolder = "J:\Receive\"
$dFolder = "J:\Receive\Decrypted\"
$aFolder = "J:\Receive\Archived\"
$Log = "J:\Receive\decrypt.log"
$gpg_p = "****"
$gpg_r = "key_id"

$recipients = @("alias@company.com")

$date = date;
Add-Content $Log $date;
Set-Location J:\

# gpg wrapper
function gpg_me {
    $in_file = $sFolder + $args[0] + ".pgp"
    $out_file = $dFolder + $args[0] + ".txt"

    #Write-Host $in_file " | " $out_file
    & $gpg_prog --batch --yes --passphrase "$gpg_p" -r "$gpg_r" -o "$out_file" -d "$in_file"

    if (!$LastExitCode) {
        Add-Content $Log "Inbound file: $in_file | Outbound file: $out_file";

        Move-Item -Path $in_file -Destination $aFolder -force
        #echo "all good" $LastExitCode
    }
}

# Loop thru current directory.
$items = Get-ChildItem -Path $sFolder
foreach ($item in $items) {
    #if the item is NOT a directory, then process it.
    if ($item.Attributes -ne "Directory") {
        #Write-Host "file found:" $item
        if ($Output = $item -like "*.pgp") {
            #Write-Host "Decrypting new file "  $item "'" $Output
            gpg_me $item.BaseName
        } else {
            # // File does not exist
            # Write-Host $item.Name " is not a file for decrypting:"
        }
    }
}

Add-Content $Log  "`n **********`n";

Write-Host "LastExitCode:" $LastExitCode
Write-Host "Output:" $Output

if ($Output -and !$LastExitCode) {
    Send-MailMessage -From "noreply@compnay.com" -SmtpServer smtp.company.com -To "$recipients" -Subject "file  received and decrypted" -Body "Decrypted file can be found at $dFolder" -Attachment $Log;
} else{
}

标签: powershellemailsyntaxnotifications

解决方案


推荐阅读