{"id":107,"date":"2007-04-10T11:00:00","date_gmt":"2007-04-10T19:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/04\/10\/updated-event-log-check\/"},"modified":"2007-04-10T11:00:00","modified_gmt":"2007-04-10T19:00:00","slug":"updated-event-log-check","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/04\/10\/updated-event-log-check\/","title":{"rendered":"Updated Event Log Check"},"content":{"rendered":"<p>A few months ago, I wrote an <a href=\"\/current\/2007\/2\/15\/powershell-quick-event-log.html\">entry<\/a> about using Powershell to look at recent event logs. Since then, I&#8217;ve decided to make a minor improvement. The new function lets you specify the number of event logs to retrieve:<\/p>\n<p><font style=\"color: #0000ff\" face=\"lucida consolne\" color=\"#0000ff\" size=\"2\">Function Show-Logs {<br \/>Param([int]$iEntries) <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"lucida consolne\" color=\"#0000ff\" size=\"2\">#default for number of entries is 5<br \/>if ($iEntries -lt 1) {$iEntries=5} <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"lucida consolne\" color=\"#0000ff\" size=\"2\">foreach ($log in (get-eventlog -list -asString)) {<br \/>&nbsp;&nbsp; Write-Host $log -fore Green -back Black; Get-eventlog $log -newest $iEntries `<br \/>&nbsp;&nbsp; |select TimeGenerated,EntryType,Source,EventID,Message | more<br \/>&nbsp; }<br \/>}<\/font> <\/p>\n<p>I&#8217;ve added this function to my Powershell profile. The new syntax is Show-Logs [number-of-entries]. I&#8217;ve added code so that if you don&#8217;t specify the number of recent entries for each log, it will default to 5: <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">if ($iEntries -lt 1) {$iEntries=5} <\/font><\/p>\n<p>Otherwise, the function will return the X number of recent event entries for each log file on your system.<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:3f3cedd4-6bba-4cca-8815-53fc7665aa75\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">Technorati tags: <\/span><a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\"><span class=\"sizeLess20\">PowerShell<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Functions\" rel=\"tag\"><span class=\"sizeLess20\">Functions<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/EventLogs\" rel=\"tag\"><span class=\"sizeLess20\">EventLogs<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Scripting\" rel=\"tag\"><span class=\"sizeLess20\">Scripting<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Get-EventLog\" rel=\"tag\"><span class=\"sizeLess20\">Get-EventLog<\/span><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A few months ago, I wrote an entry about using Powershell to look at recent event logs. Since then, I&#8217;ve decided to make a minor improvement. The new function lets you specify the number of event logs to retrieve.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}