Script not working

rated by 0 users
This post has 2 Replies | 2 Followers

Top 500 Contributor
Posts 4
aliain2003 Posted: 10-07-2010 4:32 AM

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)

Top 10 Contributor
Posts 427
Microsoft MVP
Top Contributor

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

 

 

Top 500 Contributor
Posts 4

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

Page 1 of 1 (3 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.