forked from jagilber/powershellScripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenum-eventLog-meta.ps1
166 lines (127 loc) · 4.66 KB
/
enum-eventLog-meta.ps1
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<#
.SYNOPSIS
powershell script to enumerate all event logs and enumerate all events for that event logs. Works only with newer logs
and not Classic logs.
.DESCRIPTION
Set-ExecutionPolicy Bypass -Force
This script will optionally enable / disable debug and analytic event logs.
This can be against both local and remote machines.
It will also take a regex filter pattern for eventlog names.
For each match, all event logs will be exported to csv format.
Each export will be in its own file named with the event log name.
.NOTES
File Name : enum-eventLog-meta.ps1
Author : jagilber
Version : 150822
History : 150722 original
.EXAMPLE
.\enum-eventLog-meta.ps1
#>
$logDir = "c:\temp\events"
$logfile = "$($logDir)\enum-eventLog-meta.log"
$eventList = @{}
# ----------------------------------------------------------------------------------------------------------------
function main()
{
$error.Clear()
$session = New-Object Diagnostics.Eventing.Reader.EventLogSession
if(![IO.Directory]::Exists($logDir))
{
[IO.Directory]::CreateDirectory($logDir)
}
foreach($eventLogName in $session.GetLogNames())
{
log-info "checking $($eventLogName)"
if($eventLogName.Contains("/"))
{
$eventLogName = $eventLogName.Remove($eventLogName.IndexOf("/"))
}
if(!$eventList.Contains($eventLogName))
{
$eventList.Add($eventLogName,"")
}
else
{
log-info "eventLog already processed. skipping"
continue
}
$eventLogFile = "$($logDir)\$($eventLogName).log"
$meta = $null
$meta = New-Object Diagnostics.Eventing.Reader.ProviderMetaData ($eventLogName)
if($Error)
{
$error.Clear()
continue
}
eventlog-info "Name:$($meta.Name)"
eventlog-info "Id:$($meta.Id)"
eventlog-info "MessageFilePath:$($meta.MessageFilePath)"
eventlog-info "ResourceFilePath:$($meta.ResourceFilePath)"
eventlog-info "HelpLink:$($meta.HelpLink)"
eventlog-info "# ----------------------------------------------------------------------------------------------------------------"
eventlog-info "# events"
eventlog-info "# ----------------------------------------------------------------------------------------------------------------"
foreach($event in $meta.Events)
{
eventlog-info "id:$($event.Id)"
eventlog-info "version:$($event.version)"
eventlog-info "LogLink LogName:$($event.Loglink.LogName)"
eventlog-info "LogLink DisplayName:$($eent.Loglink.DisplayName)"
eventlog-info "Level:$($event.Level.Value)"
eventlog-info "Opcode:$($event.OpCode.Value)"
eventlog-info "Task name:$($event.Task.Name)"
eventlog-info "Task event guid:$($event.Task.eventGuid)"
foreach($keyword in $event.keywords)
{
eventlog-info "Keyword name:$($keyword.Name)"
eventlog-info "Keyword value:$($keyword.Value)"
}
eventlog-info "Template:$($event.Template)"
eventlog-info "Description:$($event.Description)"
eventlog-info "# ----------------------------------------------------------------------------------------------------------------"
}
}
}
# ----------------------------------------------------------------------------------------------------------------
function eventLog-info($data)
{
$dataWritten = $false
#Write-Host $data
$counter = 0
while(!$dataWritten -and $counter -lt 1000)
{
try
{
out-file -Append -InputObject $data -FilePath $eventLogFile
$dataWritten = $true
}
catch
{
Start-Sleep -Milliseconds 10
$counter++
}
}
}
# ----------------------------------------------------------------------------------------------------------------
function log-info($data)
{
$dataWritten = $false
$data = "$([System.DateTime]::Now):$($data)`n"
Write-Host $data
$counter = 0
while(!$dataWritten -and $counter -lt 1000)
{
try
{
out-file -Append -InputObject $data -FilePath $logFile
$dataWritten = $true
}
catch
{
Start-Sleep -Milliseconds 10
$counter++
}
}
}
# ----------------------------------------------------------------------------------------------------------------
main