Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $EventLogDir = "C:\CustomEventLog"
  2. $systemfile = "C:\CustomEventLog\system.txt"
  3. $applicationfile = "C:\CustomEventLog\application.txt"
  4. $systemvariables =  "C:\CustomEventLog\variables.txt"
  5. $computername = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
  6. mkdir $EventLogDir
  7.  
  8. Get-EventLog -LogName system -EntryType Error -after ([datetime]::Today) | fl | out-file $systemfile
  9. Get-EventLog -LogName application -EntryType Error -after ([datetime]::Today) | fl | out-file $applicationfile
  10. Get-ChildItem env: | fl | out-file $systemvariables
  11.  
  12. #Connection Details
  13. $username="email@address.com"
  14. $password="password"
  15. $smtpServer = "smtp-mail.outlook.com"
  16. $msg = new-object Net.Mail.MailMessage
  17.  
  18. #Change port number for SSL to 587
  19. $smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  20.  
  21. #Uncomment Next line for SSL
  22. $smtp.EnableSsl = $true
  23.  
  24. $smtp.Credentials = New-Object System.Net.NetworkCredential( $username, $password )
  25.  
  26. #From Address
  27. $msg.From = "email@address.com"
  28. #To Address, Copy the below line for multiple recipients
  29. $msg.To.Add("to-email@address.com")
  30.  
  31. #Message Body
  32. $msg.Body="Please See log files for review","Computer: $computername"
  33.  
  34. #Message Subject
  35. $msg.Subject = "Event and Applications Logs - $computername"
  36.  
  37. #your file location
  38. $files=Get-ChildItem "$EventLogDir"
  39.  
  40. Foreach($file in $files)
  41. {
  42. $attachment = new-object Net.Mail.Attachment -ArgumentList $file.FullName
  43. $msg.Attachments.Add($attachment)
  44.  
  45. }
  46. $smtp.Send($msg)
  47. $attachment.Dispose();
  48. $msg.Dispose();
  49.  
  50.  
  51. # Cleanup
  52. rmdir -r $EventLogDir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement