Hey I'm back with a query again
I'm able to get a script run on 4 vcenters..
is there a way to get all the outputs as attachments in a single email?? I don't want 4 emails every day
VMSavvy.
you can use like below ones...
$att = new-object Net.Mail.Attachment(”E:\filename“)
$att1 = new-object Net.Mail.Attachment(”E:\filename“)
$msg.Attachments.Add($att)
$msg.Attachments.Add($att1)
Hi VMSavvy,
I've just found this post http://www.searchmarked.com/windows/how-to-send-an-email-using-a-windows-powershell-script.php
You can find there the following code snipet:
$filename = “logfile.txt”
$smtpServer = “localhost”
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “somebody@yourdomain.com”
$msg.To.Add(”somebody@theirdomain.com”)
$msg.Subject = “Nightly Log File”
$msg.Body = “The nightly log file is attached”
$msg.Attachments.Add($att)
$smtp.Send($msg)
So you can add as many attachments as you like
If you have any other questions don't hesitate to ask.
Thanks,
Nedko
Thanks Nedko..
I'm using this already.. but I get my output into say $filelocation.. the script runs on 4 different vcenters.. so 4 output files are created.. I think I'll get 4 different emails (correct me if I'm wrong)..
so just thinking to see if I can get something like $files = (a code which can club all the outputs) and put $files into the $att to get one email with 4 attachments..
not sure if I explained clearly..
VMSavvy..
you can use like below ones...
$att = new-object Net.Mail.Attachment(”E:\filename“)
$att1 = new-object Net.Mail.Attachment(”E:\filename“)
$msg.Attachments.Add($att)
$msg.Attachments.Add($att1)
That worked. Thanks all!!
VMSavvy..