Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $EventLogDir = "C:\CustomEventLog"
- $systemfile = "C:\CustomEventLog\system.txt"
- $applicationfile = "C:\CustomEventLog\application.txt"
- $systemvariables = "C:\CustomEventLog\variables.txt"
- $computername = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
- mkdir $EventLogDir
- Get-EventLog -LogName system -EntryType Error -after ([datetime]::Today) | fl | out-file $systemfile
- Get-EventLog -LogName application -EntryType Error -after ([datetime]::Today) | fl | out-file $applicationfile
- Get-ChildItem env: | fl | out-file $systemvariables
- #Connection Details
- $username="email@address.com"
- $password="password"
- $smtpServer = "smtp-mail.outlook.com"
- $msg = new-object Net.Mail.MailMessage
- #Change port number for SSL to 587
- $smtp = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
- #Uncomment Next line for SSL
- $smtp.EnableSsl = $true
- $smtp.Credentials = New-Object System.Net.NetworkCredential( $username, $password )
- #From Address
- $msg.From = "email@address.com"
- #To Address, Copy the below line for multiple recipients
- $msg.To.Add("to-email@address.com")
- #Message Body
- $msg.Body="Please See log files for review","Computer: $computername"
- #Message Subject
- $msg.Subject = "Event and Applications Logs - $computername"
- #your file location
- $files=Get-ChildItem "$EventLogDir"
- Foreach($file in $files)
- {
- $attachment = new-object Net.Mail.Attachment -ArgumentList $file.FullName
- $msg.Attachments.Add($attachment)
- }
- $smtp.Send($msg)
- $attachment.Dispose();
- $msg.Dispose();
- # Cleanup
- rmdir -r $EventLogDir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement