Thursday, April 26, 2012

Scripting Games 2012 Advanced Event 7

Advanced Event 7 :

<#
.DESCRIPTION
    This script reports latest events from all event logs.
.LINK
    http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/10/the-2012-scripting-games-advanced-event-7-search-windows-logs.aspx
#>
$obj=@()
Get-WinEvent -ea silentlycontinue -ListLog * -Force | where { $_.isEnabled -eq $true } `
         | foreach {
                        if (!(($_.logtype -eq "analytical") -or ($_.logtype -eq "debug")))
                        {
                          
                            $obj += (Get-WinEvent -ea silentlycontinue -LogName $_.logname -MaxEvents 1 `
                                                     | Select-Object TimeCreated,Logname,ID,Message)  
                           
                        }
                        else
                        {
                            $debevents=@()
                            $debevents = (Get-WinEvent -ea silentlycontinue -LogName $_.logname -Force -Oldest `
                                                    | Select-Object TimeCreated,Logname,ID,Message )
                            $obj += $debevents[-1]
                        }
                  
                   }
         
Write-Output $obj | Sort-Object timecreated -Descending | Fl *
               

No comments:

Post a Comment