0
votes

My subject is probably not worded correctly.

I am working on some scripts and using the "Send-MailMessage" command. I need to have some variables in the body of the message.... How can I do this? These variables are directories, log file locations, IP addresses, etc from the script. When the script finishes or fails I need to send an email with pertinent info about the job..

$bod = "this is message please see log file at $logfilelocation"

Send-MailMessage -To [email protected] -Subject subject -From [email protected] -body $bod -SmtpServer server

1

1 Answers

2
votes

You've already got the right idea. You just need to build up your $bod string using the variables. A 'here' string would probably work well. Something like:

$bod=@"
directory: $directory
log file location: $logfileLocation
ip address: $ipAddress
"@

Or are you asking how to get those values into variables?