I would send me the vmkwarning logs per email:
foreach ($vmhost in get-cluster cluster04 | get-vmhost){ $log = get-log -key vmkwarning $vmhost $mailBody = $mailBody` + $log.entries } $mailBody
But then the log entries are all on one line. How could I format this nicer?
Thanks, Daniel
Try this
$mailbody = @() foreach ($vmhost in get-cluster | get-vmhost){ $log = get-log -key vmkernel $vmhost $log.Entries | %{ $mailbody += ("`r`n" + $_) } } # Send report via email $SmtpClient = New-Object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.host = <smtp-server> $MailMessage.from = <from-address> $MailMessage.To.add(<to-address>) $MailMessage.Subject = "logs" $MailMessage.body = $mailBody $SmtpClient.Send($MailMessage)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-Log for all VMHosts
$mailbody = Get-VMHost | Get-Log -Key vmkwarning | % { $_.Entries }
Get-Log for all VMHosts in Cluster
$mailbody = Get-Cluster <clustername> | Get-VMHost | Get-Log -Key vmkwarning | % { $_.Entries }
Thanks, this is a lot easier way. But the result is the same. If I generate a mail with the variable $mailbody as mailtext I loose the newlines.
Is there a way to remain them?
Try this
$mailbody = @() foreach ($vmhost in get-cluster | get-vmhost){ $log = get-log -key vmkernel $vmhost $log.Entries | %{ $mailbody += ("`r`n" + $_) } } # Send report via email $SmtpClient = New-Object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.host = <smtp-server> $MailMessage.from = <from-address> $MailMessage.To.add(<to-address>) $MailMessage.Subject = "logs" $MailMessage.body = $mailBody $SmtpClient.Send($MailMessage)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, this one works as expected.
I modified it a bit:
$mailbody = @() foreach ($vmhost in get-cluster | get-vmhost | sort-object){ $log = get-log -key vmkwarning $vmhost if ($log.Entries -ne "") { $mailbody += ("`r`n" + $vmhost + ":") } $log.Entries | %{ $mailbody += ("`r`n" + $_) } } ...
Hit Correct Answer for LucD --so others know its been answered
I did this already!