windows - powershell 脚本 - 每周发送一次电子邮件,其中包含来自事件查看器的信息
问题描述
我的老板要求我提供一个脚本,该脚本每周向他发送一次电子邮件,内容是关于公司中 Windows 防病毒软件已隔离文件(在过去一周内)的计算机,并将其记录在某个地方。虽然我确实找到了如何找到这些事件:
Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | Where-Object {$_.id -eq
1116}
我现在有点迷茫,可以真正使用和建议。我现在应该如何处理?有人做过类似的事情谁能给我建议?非常感谢提前
解决方案
# Get events and filter by id and TimeCreated (last 7 days)
# Also filter by TimeCreated and Message columns
$events = Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" |
Where-Object {($_.id -eq 1116) -and ($_.TimeCreated -gt ((Get-Date).AddDays(-7)))} |
select TimeCreated, Message |
Format-List |
Out-String
# Message Data
$emailFrom = "noreply@domain.com"
$emailTo = "foo@domain.com"
$subject = "Computers where windows antivirus have quarantined files"
# Send message to smtpserver.domain.local (local network)
$smtpServer = "smtpserver.domain.local"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $events)
推荐阅读
- lucene - Apache Ignite 中的 TEXT 查询没有给出任何结果
- php - 在wordpress中的页码后添加URL参数
- javascript - 以更有效的方式使用 Javascript 更改 CSS 属性
- java - 无法在提供的参数值中找到“in_id”的相应参数值
- php - 使用 composer 安装 Laravel 编译资源(Mix)
- sql - MS SQL:通过包含新表中的其他列来更改索引视图
- c# - 如何在 Visual Studio 2017 中使用 gRPC 模板?
- php - 我在将数据从 PHP 更新到我的 SQL 数据库时发现了一个问题,我想根据学生 ID 进行更新
- ajax - 重新加载页面后 Ajax 查询不起作用
- php - 在 Woocommerce 中添加产品属性列以编辑订单页面