该脚本在触发特定事件时发送电子邮件。 当我在FSRM上configuration的文件屏幕检测到用户保存特定文件types时,我正在运行此脚本。 命令选项卡是我运行powershell.exe和这个脚本的参数。 我试图从事件日志中添加我的文件屏幕configuration生成的消息。 但是,当此脚本生成电子邮件时,它会生成以下内容而不是事件消息。
System.Diagnostics.EventLogEntry
这是脚本:
function sendMail{ Write-Host “Sending Email” #SMTP server name $smtpServer = “smtp.abc.com” #Creating a Mail object $msg = new-object Net.Mail.MailMessage #gets the server name $srv = $env:computername #gets the event ID details $event = Get-Eventlog -LogName Application -source SRMSVC -Newest 1 #Creating SMTP server object $smtp = new-object Net.Mail.SmtpClient($smtpServer) #Email structure $msg.From = “[email protected]“ $msg.ReplyTo = “[email protected]“ $msg.To.Add(“[email protected]“) $msg.subject = “Event Alert” $msg.body = “The file resource management service has detected activity. Please check the appliction log on $srv and look for id 8215. Here are the event details $event ” #Sending email $smtp.Send($msg) } #Calling function sendMail
通过将正确的计算机名称添加到电子邮件正文,可正确input$ srvvariables。
有谁知道为什么事件消息没有被包含在电子邮件的正文中吗?
尝试改变
$msg.body = “The file resource management service has detected activity. Please check the appliction log on $srv and look for id 8215. Here are the event details $event ”
至
$msg.body = “The file resource management service has detected activity. Please check the appliction log on $srv and look for id 8215. Here are the event details $($event.message) ”
我所做的就是将$event改为$($event.message)