-
Notifications
You must be signed in to change notification settings - Fork 0
/
Export-WinEventLogToCsv.ps1
70 lines (54 loc) · 1.92 KB
/
Export-WinEventLogToCsv.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
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $EventLogName,
[Parameter(Mandatory = $false)]
[string] $OutputFilePath
)
if (-not $PSBoundParameters.ContainsKey('OutputFilePath'))
{
$OutputFilePath = Join-Path -Path $PSScriptRoot -ChildPath ('{0}_{1}.tsv' -f $env:ComputerName, ($eventLogName -replace '/', '_'))
}
Get-WinEvent -LogName $EventLogName |
ForEach-Object -Process {
$properties = ''
$_.Properties |
ForEach-Object -Process {
$properties += "`n" + $_.Value
}
$keywordsDisplayNames = ''
$_.KeywordsDisplayNames |
ForEach-Object -Process {
$keywordsDisplayNames += "`n" + $_.Value
}
[PSCustomObject]@{
RecordId = $_.RecordId
TimeCreated = $_.TimeCreated
Level = $_.Level
LevelDisplayName = $_.LevelDisplayName
Opcode = $_.Opcode
OpcodeDisplayName = $_.OpcodeDisplayName
EventId = $_.Id
Task = $_.Task
TaskDisplayName = $_.TaskDisplayName
Message = $_.Message
UserId = $_.UserId
ProcessId = $_.ProcessId
ThreadId = $_.ThreadId
MachineName = $_.MachineName
Properties = $properties
LogName = $_.LogName
ContainerLog = $_.ContainerLog
ProviderId = $_.ProviderId
ProviderName = $_.ProviderName
Keywords = $_.Keywords
Qualifiers = $_.Qualifiers
Version = $_.Version
ActivityId = $_.ActivityId
RelatedActivityId = $_.RelatedActivityId
MatchedQueryIds = $_.MatchedQueryIds -join ','
KeywordsDisplayNames = $keywordsDisplayNames
#Bookmark = $_.Bookmark
}
} |
Export-Csv -NoTypeInformation -Delimiter "`t" -Encoding UTF8 -LiteralPath $OutputFilePath