This script is sending an email when a particular event is triggered. I am running this script when a file screen i have configured on FSRM detects a user saving specific file types. The command tab is where I am running powershell.exe and for the arguments this script. I am trying to add the message from the event log that my file screen is configured to generate. However, when this script generates the email it generates the following instead of the event message.
System.Diagnostics.EventLogEntry
Here is the script:
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
The $srv variable is entered properly by adding the correct computer name to the body of the email.
Does anyone know why the event message is not being included in the body of the email instead?
$event
with$event|Get-Member
you might see what you are missing.