从Powershell通过电子邮件发送输出

时间:2018-05-22 20:07:57

标签: powershell email output send

See attached photo (link) of Output in PowerShell and Outlook.

我正在尝试通过电子邮件发送输出,但是让脚本将输出放在电子邮件正文中时遇到了麻烦。它不是抓住所需阈值(70天)之间的服务名称和过期日期,而是抓取CSV中的所有内容(例如,查看2022年到期的服务)并将其放入电子邮件正文中。

我的问题是我如何通过电子邮件发送我在PowerShell中提取的信息(那些介于指定阈值日期之间的信息)?

脚本编写有点新,谢谢! :)

$now=get-date
$cert = Import-Csv C:\Users\userID\Desktop\Certificate_CSV2.csv
$threshold = 70  
$deadline = (Get-Date).AddDays($threshold) 
$cert | Select-Object "Service Name", "Certificate Expiration Date" | Where-Object {$_."Certificate Expiration Date" -as [datetime] -le $deadline} 

Send-mailMessage -to "SentTo@email.com" -subject "test message 8" -from "SentTo@email.com" -body ($cert | Out-String) -SmtpServer pobox.email.com

1 个答案:

答案 0 :(得分:2)

您只是使用过滤器打印出证书,而不是将其应用回证书。要修复,只需将$ cert设置为自身的过滤版本。

$cert = $cert | Select-Object "Service Name", "Certificate Expiration Date" | Where-Object {$_."Certificate Expiration Date" -as [datetime] -le $deadline} 
相关问题