Hi,
Im new to powershell, I have writtien the following script which seems to run OK except it doesn't pull the information back. Any help would be greatly received.
clear-host$date1 = (Get-date).adddays(-1)$computers = "C:\scripts\Powershell\pac\computers2003.txt"$SmtpServer = ""$To = ""$From = ""$Subject = "application Event Log Errors for windows 2003 servers" $a = get-eventlog "application" -computername (get-content $computers) -after $date1 | ?{ $_.EntryType -eq "Error" } | ` Select-Object EventID, MachineName, EntryType, Message, ` Source, Username | ` ConvertTo-HTML $MailMessage = New-object Net.Mail.MailMessage(` $To, ` $From, ` $Subject, ` $a )$MailMessage.IsBodyHTML = $True $SmtpClient = New-Object Net.Mail.SmtpClient($SmtpServer)$SmtpClient.Send($MailMessage)
You could use new PowerShell V2 cmdlet - Send-MailMessage:
PS> Send-MailMessage -To "recipient@test.local" -from "sender@test.local" -body "$a" -subject test -smtpserver YourSMTPServer -BodyAsHtml
Thanks for the tip,
I don't have an issue with the scrip sending an email, it emails out to the group fine, just the email does not contain any log details.
so it just sends a blank email.
thanks