Windows powershell脚本-每周发送一次包含事件查看器信息的电子邮件

Windows powershell脚本-每周发送一次包含事件查看器信息的电子邮件,windows,powershell,events,logging,server,Windows,Powershell,Events,Logging,Server,老板向我要了一份脚本,每周给他发一次电子邮件,内容是关于windows antivirus(在过去一周)隔离文件的公司的计算机,并将其记录在某个地方。 虽然我确实找到了如何找到这些事件: Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational" | Where-Object {$_.id -eq 1116} 我现在有点迷路了,我真的需要你的帮助和建议。我现在应该如何处理这个问题?有谁做过类似的事情谁能给我建

老板向我要了一份脚本,每周给他发一次电子邮件,内容是关于windows antivirus(在过去一周)隔离文件的公司的计算机,并将其记录在某个地方。 虽然我确实找到了如何找到这些事件:

Get-WinEvent -LogName "Microsoft-Windows-Windows Defender/Operational"  | Where-Object {$_.id -eq 
1116}
我现在有点迷路了,我真的需要你的帮助和建议。我现在应该如何处理这个问题?有谁做过类似的事情谁能给我建议?
提前非常感谢

查看
获取帮助*邮件*
。然后使用内置的windows调度程序每隔一段时间运行一次。[咧嘴笑]泰,我会在获得15次代表票并投票决定答案后再谈这个问题
# 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)