Eventvwr.exe в почту
Логи можно просматривать руками, но лучше когда все самое важное приходит к тебе на почту! 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
Set-ExecutionPolicy RemoteSigned -Scope currentuser $compname = $(Get-WmiObject Win32_Computersystem).name $FileSecurity = "C:\Logs\Security.txt" Get-EventLog Security -After (Get-date -hour 0 -minute 0 -second 0) | where {$_.EntryType -eq "Error" -or $_.EntryType -eq "Warning" -or $_.EntryType -eq "Critical"} | Out-File -FilePath $FileSecurity -encoding UTF8 -width 500 $FileApplication = "C:\Logs\Application.txt" Get-EventLog Application -After (Get-date -hour 0 -minute 0 -second 0) | where {$_.EntryType -eq "Error" -or $_.EntryType -eq "Warning" -or $_.EntryType -eq "Critical"} | Out-File -FilePath $FileApplication -encoding UTF8 -width 500 $FileSystem = "C:\Logs\System.txt" Get-EventLog System -After (Get-date -hour 0 -minute 0 -second 0) | where {$_.EntryType -eq "Error" -or $_.EntryType -eq "Warning" -or $_.EntryType -eq "Critical"} | Out-File -FilePath $FileSystem -encoding UTF8 -width 500 $FileHardwareEvents = "C:\Logs\HardwareEvents.txt" Get-EventLog HardwareEvents -After (Get-date -hour 0 -minute 0 -second 0) | where {$_.EntryType -eq "Error" -or $_.EntryType -eq "Warning" -or $_.EntryType -eq "Critical"} | Out-File -FilePath $FileHardwareEvents -encoding UTF8 -width 500 $Folder = "C:\Logs" #Путь к папке для сохранения логов $Archive = "C:\Logs\Logs.rar" $rar = 'C:\Program Files (x86)\WinRAR\Rar.exe' &$rar a "$Archive" $Folder Start-Sleep -Seconds 60 $From = "От кого" $To = "Кому" $SMTPServer = "smtp сервер" $SMTPPort = "Порт сервера smtp" $Username = "Имя пользователя" $Password = "Пароль" $subject = "$compname - логи за сутки" $body = "Смотри вложение" $EmailAttachment = "C:\Logs\Logs.rar" $message = New-Object System.Net.Mail.MailMessage $From, $To $message.Subject = $subject $message.IsBodyHTML = $true $message.Body = $body $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort) $smtp.EnableSSL = $true $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password) $Attachment = New-Object System.Net.Mail.Attachment($EmailAttachment, 'text/plain') $message.Attachments.Add($Attachment) $smtp.Send($message) Start-Sleep -Seconds 60 Remove-Item C:\Logs\*.* #Есть необходимость? |