{"id":350,"date":"2012-05-11T18:13:21","date_gmt":"2012-05-11T14:13:21","guid":{"rendered":"http:\/\/samara-it.ru\/?p=350"},"modified":"2012-05-11T18:13:21","modified_gmt":"2012-05-11T14:13:21","slug":"%d0%90%d0%bd%d0%b0%d0%bb%d0%b8%d0%b7%d0%b8%d1%80%d1%83%d0%b5%d0%bc-%d0%b6%d1%83%d1%80%d0%bd%d0%b0%d0%bb-%d0%bd%d0%b0-%d1%83%d0%b4%d0%b0%d0%bb%d0%b5%d0%bd%d0%bd%d1%8b%d1%85-%d1%81%d0%b5%d1%80%d0%b2","status":"publish","type":"post","link":"https:\/\/www.samara-it.ru\/?p=350","title":{"rendered":"\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0436\u0443\u0440\u043d\u0430\u043b \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445."},"content":{"rendered":"<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0447\u0442\u0435\u043d\u0438\u0438 \u0436\u0443\u0440\u043d\u0430\u043b\u043e\u0432.<br \/>\n\u041f\u0440\u0438\u0437\u043d\u0430\u0439\u0442\u0435\u0441\u044c, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u044b \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0436\u0443\u0440\u043d\u0430\u043b\u043e\u0432 \u0432 windows? \u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 &#171;\u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438&#187; \u0432 \u0436\u0443\u0440\u043d\u0430\u043b\u0435? \u0412\u0435\u0434\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0435\u0433\u0447\u0435, \u0447\u0435\u043c \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u043c. \u0422\u0435\u043c \u0431\u043e\u043b\u0435\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0443 \u043d\u0430\u0441 \u043c\u043d\u043e\u0433\u043e. \u041d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0439\u0442\u0438 PowerShell. \u0423 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430<\/p>\n<pre lang=\"powershell\" escaped=\"true\">Get-EventLog<\/pre>\n<p>\u0412\u043e\u0442 \u0441 \u0435\u0435 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438 \u0431\u0443\u0434\u0435\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0436\u0443\u0440\u043d\u0430\u043b\u044b.<br \/>\n\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0432 \u0448\u0435\u0434\u0443\u043b\u043b\u0435\u0440 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u043e\u043c \u0440\u0430\u0437 \u0432 \u0447\u0430\u0441 \u043d\u0443 \u0438\u043b\u0438 \u0440\u0430\u0437 \u0432 \u0441\u0443\u0442\u043a\u0438, \u043a\u043e\u043c\u0443 \u043a\u0430\u043a \u043d\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f. \u0412\u0441\u0435 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0424\u0430\u0439\u043b &#171;server_all.txt&#187; \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u0430\u043a \u044f \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 <a href=\"http:\/\/samara-it.ru\/?p=244\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a>.<\/p>\n<pre lang=\"powershell\" escaped=\"true\">\r\n<# \r\n\u0421\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \"\u041e\u0448\u0438\u0431\u043e\u043a\" \u0438 \"\u041f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439\" \u0438\u0437 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 \"System\" \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0430\u0439\u043b\u0435 $srv\r\n\u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0447\u0430\u0441, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 admin@mycompany.com\r\n-------------------\r\n\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438:\r\n\u0441\u043c: AddHours(-1) - \u0432\u0440\u0435\u043c\u044f \u0437\u0430 \u043a\u0430\u043a\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\r\n\u0441\u043c: -LogName \"System\" -EntryType \"Error\" , \"Warning\" - \u0436\u0443\u0440\u043d\u0430\u043b, \u0438 \u0442\u0438\u043f\u044b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439\r\n\u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u0447\u0442\u044b - \u0441\u043c. \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0446\u0435.\r\n#>\r\n\r\ncls\r\n\r\n$srv = Get-Content \"c:\\[path]\\server_all.txt\"\r\n\r\n$dt = Get-Date\r\n\r\n$outHTML = \"\"\r\n$outHTML += '<!DOCTYPE HTML PUBLIC \\\"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\\\">'\r\n$outHTML += '<html>'\r\n$outHTML += '<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/>'\r\n$outHTML += '<h2 align=\"center\">\u041e\u0442\u0447\u0435\u0442 \u0437\u0430 ' + $dt.ToString('dd\/MM\/yyyy HH:mm') + '<\/h2>'\r\n$outHTML += '<table width=\"100%\" border=\"1\" cellspacing=\"2\" cellpadding=\"2\"  align=\"center\">'\r\n$outHTML += '<tr><th>\u2116<\/th><th>Date<\/th><th>Computer<\/th><th>Type<\/th><th>EventID<\/th><th>Source<\/th><th>User<\/th><th>Message<\/th><\/tr>'\r\n\r\n$ok = 0\r\n\r\n#\u0417\u0430\u0431\u0438\u0432\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438\r\nforeach ($var in $srv) {\r\n\r\n\t# \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439, \u0435\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 #- \u0437\u043d\u0430\u0447\u0438\u0442 \u044d\u0442\u043e \u043a\u043e\u043c\u0435\u043d\u0442. \u0438\u043b\u0438 \u043f\u0443\u0441\u0442\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443\r\n\tif (($var -notmatch \"#\") -and ($var.Length -ne 0)){\r\n\r\n\t\t$out = $var -split \";\"\r\n\t\t\r\n\t\t$password = $out[1] | ConvertTo-SecureString \r\n\t\t$cred = New-Object System.Management.Automation.PSCredential $out[0],$password\r\n\t\t\r\n\t\t$s = $out[2] -split \",\"\r\n\t\t$session = New-PSSession -ComputerName $s -Credential $cred\r\n\r\n\t\t# \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\r\n\t\tInvoke-Command -Session $session {$dtNow = Get-Date}\r\n\t\tInvoke-Command -Session $session {$dtPrev = $dtNow.AddHours(-1)}\r\n\t\tInvoke-Command -Session $session {$EventLog = get-eventlog -LogName \"System\" -EntryType \"Error\" , \"Warning\"}\r\n\t\t$result = Invoke-Command -Session $session {$EventLog | Where-Object {$_.TimeWritten -le $dtNow -and $_.TimeWritten -ge $dtPrev} }\r\n\r\n\t\t# \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\r\n\t\tif ($result.Count -ge 0){\r\n\t\t\t$ok = 1\r\n\t\t\t\t\t\t\r\n\t\t\tfor ($i=0; $i -lt $result.Count; $i++){\r\n\t\t\t\r\n\t\t\t\t$outHTML += '<tr align=\"left\">'\r\n\t\t\t\t$outHTML += '<td>' + $i + '<\/td>'\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].TimeWritten + '&nbsp;<\/td>'\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].PSComputerName + '&nbsp;<\/td>'\r\n\t\t\t\t\r\n\t\t\t\tif ($result.SyncRoot[$i].EntryType -eq 'Error'){\r\n\t\t\t\t\t$outHTML += '<td bgcolor=\"#FF0000\"><b>' + $result.SyncRoot[$i].EntryType + '<\/b>&nbsp;<\/td>'\t\t\t\t\r\n\t\t\t\t}else{\r\n\t\t\t\t\t$outHTML += '<td bgcolor=\"#FFFF00\"><b>' + $result.SyncRoot[$i].EntryType + '<\/b>&nbsp;<\/td>'\t\t\t\t\r\n\t\t\t\t}\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].EventID + '&nbsp;<\/td>'\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].Source + '&nbsp;<\/td>'\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].UserName + '&nbsp;<\/td>'\r\n\t\t\t\t$outHTML += '<td>' + $result.SyncRoot[$i].Message + '&nbsp;<\/td>'\r\n\t\t\t\t$outHTML += '<\/tr>'\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\t#\u0412\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 \u0441\u0435\u0441\u0441\u0438\u0438.\r\n\t\tRemove-PSSession -Session $session\r\n\t}\r\n}\r\n\r\n$outHTML += '<\/table><\/html>'\r\n\r\nif ($ok -eq 1){\r\n\t# \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043e\u0447\u0442\u0443\r\n\t$SMTPClient          = new-object System.Net.Mail.SMTPClient \r\n\t$Msg                 = new-object System.Net.Mail.MailMessage \r\n\t$Msg.From            = \"robot@mycompany.com\" \r\n\t$Msg.Subject         = '[Event Log] ' + $dt.ToString('dd\/MM\/yyyy HH:mm')\r\n\t$Msg.IsBodyHTML      = 1 \r\n\t$Msg.BodyEncoding    = [System.Text.Encoding]::UTF8\r\n\t$Msg.Body            = $outHTML\r\n\t$SMTPClient.Host     = 'host.mycompany.com' \r\n\t$SMTPClient.Port     = 25 \r\n\t$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(\"robot@mycompany.com\", \"Pa$SWorD\")\r\n\t$Msg.To.Add('admin@mycompany.com') \r\n\t$SMTPClient.Send($Msg) \r\n}\r\n<\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u043e, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<br \/>\n<!DOCTYPE HTML PUBLIC \\\"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\\\"><br \/>\n<html><meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/><\/p>\n<h2 align=\"center\">\u041e\u0442\u0447\u0435\u0442 \u0437\u0430 11.05.2012 13:00<\/h2>\n<table width=\"100%\" border=\"1\" cellspacing=\"2\" cellpadding=\"2\"  align=\"center\">\n<tr>\n<th>\u2116<\/th>\n<th>Date<\/th>\n<th>Computer<\/th>\n<th>Type<\/th>\n<th>EventID<\/th>\n<th>Source<\/th>\n<th>User<\/th>\n<th>Message<\/th>\n<\/tr>\n<tr align=\"left\">\n<td>0<\/td>\n<td>05\/11\/2012 13:00:04&nbsp;<\/td>\n<td>server10&nbsp;<\/td>\n<td bgcolor=\"#FF0000\"><b>Error<\/b>&nbsp;<\/td>\n<td>56&nbsp;<\/td>\n<td>TermDD&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<td><span lang=\"ru\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/span><\/td>\n<\/tr>\n<tr align=\"left\">\n<td>1<\/td>\n<td>05\/11\/2012 13:00:15&nbsp;<\/td>\n<td>server3<\/td>\n<td bgcolor=\"#FF0000\"><b>Error<\/b>&nbsp;<\/td>\n<td>56&nbsp;<\/td>\n<td>TermDD&nbsp;<\/td>\n<td>&nbsp;<\/td>\n<td><span lang=\"ru\">\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438.<\/span><\/td>\n<\/tr>\n<\/table>\n<p><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u0446\u0438\u043a\u043b \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e \u0447\u0442\u0435\u043d\u0438\u0438 \u0436\u0443\u0440\u043d\u0430\u043b\u043e\u0432. \u041f\u0440\u0438\u0437\u043d\u0430\u0439\u0442\u0435\u0441\u044c, \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u043e \u0432\u044b \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0436\u0443\u0440\u043d\u0430\u043b\u043e\u0432 \u0432 windows? \u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c. \u0410 \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u043f\u0438\u0441\u044c\u043c\u0430 \u0441 &#171;\u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438&#187; \u0432 \u0436\u0443\u0440\u043d\u0430\u043b\u0435? \u0412\u0435\u0434\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0443 \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0435\u0433\u0447\u0435, \u0447\u0435\u043c \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u0438 \u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0430\u043c.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.samara-it.ru\/?p=350\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":306,"comment_status":"close","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-win"],"_links":{"self":[{"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350"}],"version-history":[{"count":22,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions"}],"predecessor-version":[{"id":372,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions\/372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=\/wp\/v2\/media\/306"}],"wp:attachment":[{"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.samara-it.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}