powershell - gpg解密和邮件通知
问题描述
我遇到的两个问题是,
它完成了这项工作,但引发了如下所示的错误。
通知不会触发,根本不满足条件。
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{
}
解决方案
推荐阅读
- ruby-on-rails - 是否可以在生产环境中使用 Rails、Webpacker 将 Vue.js 组件挂载到 DOM 上?
- python-3.x - 如何使用 Pandas 作为函数将数值重新分类到新的分组中,没有条件限制
- ruby-on-rails - Rails 和 Rspec 单元测试静态方法
- ios - iOS PDFKit - 宽度问题
- javascript - HTML 防盗
- python - 使用模拟数据进行深度学习
- python - 如何随机化 if/elif 语句的顺序?
- drools - Drools 为 StatelessKieSession 的列表输入中的每个项目触发一个规则
- sql - 重叠日期范围总结
- javascript - A-Frame:以编程方式拍摄全景截图