-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamples.ps1
206 lines (136 loc) · 6.98 KB
/
Examples.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#TimeBomb
Write-Host "You have 20 seconds left" -ForegroundColor Yellow
Start-Sleep -Seconds 20
$filepath = 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes\'
Set-Location -Path $filepath
#break
# Dot Sourcing
#. '.\LogFileParser\LogFileParser.ps1'
#. '.\LogFileParser\LogFileParser - Add Robo1.ps1'
. '.\LogFileParser\LogFileParser - Add Robo2.ps1'
# loading complete directory recursive
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\Mix\")
# loading a specific file
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\CBS\cbs.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\DISM\dism.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\WindowsUpdateLog\WindowsUpdate.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\Upgrade\setupact.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\Upgrade\setuperr.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\SCCM\ccmexec.log")
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\Robocopy\Robocopy.log")
####################################################################################################
#region data
# information of current data
$newLogParser
$newLogParser.ParsedLogFiles
$newLogParser.LogFileTypeClasses | select * -ExpandProperty LoadedClasses
$newLogParser.ParsedLogFiles | Select-Object -Property LogFilePath, LogFileType
# show data
$newLogParser.ParsedLogFiles[0].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[1].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[2].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[3].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[4].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[5].ParsedLogData | Out-GridView
$newLogParser.ParsedLogFiles[6].ParsedLogData | Out-GridView
($newLogParser.ParsedLogFiles[0].ParsedLogData.RowNum | Measure -Maximum).Maximum
# columns of data, which can be used for conditions
$newLogParser.ParsedLogFiles[0].GetColumnNames()
# Gets lines with errors
$newLogParser.ParsedLogFiles[0].GetLinesWithErrors() | Out-GridView
# Gets lines with warnings
$newLogParser.ParsedLogFiles[1].GetLinesWithWarnings() | Out-GridView
# gather only rows, which contain errors and show also all 8 lines before and after the error-lines
$newLogParser.ParsedLogFiles[0].GetLinesWithErrorsWithRange(8) | Out-GridView
# gather only rows, which contain warnings and show also all 8 lines before and after the warning-lines
$newLogParser.ParsedLogFiles[1].GetLinesWithWarningsWithRange(8) | Out-GridView
# columns of data, which can be used for conditions
$newLogParser.ParsedLogFiles[0].GetColumnNames()
# gather only rows, which contain errors and show them
($newLogParser.ParsedLogFiles[0].ParsedLogData).Where{
$_.($newLogParser.ParsedLogFiles[0].DataField) -like '*0x8*'
} | Out-GridView
#Row conditions
($newLogParser.ParsedLogFiles[0].ParsedLogData).Where{
$_.RowNum -gt 10 -and $_.RowNum -lt 50
} | Out-GridView
#Time conditions
($newLogParser.ParsedLogFiles[0].ParsedLogData).DateTime
#last 500 days
($newLogParser.ParsedLogFiles[0].ParsedLogData).Where{
$_.DateTime -gt ([DateTime]::Now).AddDays(-500)
}
#endregion
####################################################################################################
#Special functions
($newLogParser.ParsedLogFiles[6]).GetInstalledUpdates() | Out-GridView
####################################################################################################
# Dot Sourcing
. '.\LogFileParser\LogFileParser.ps1'
. '.\LogFileParser\LogFileParser - Add Robo1.ps1'
. '.\LogFileParser\LogFileParser - Add Robo2.ps1'
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\Robocopy\robocopy.log")
####################################################################################################
#Class information
[LogFileTypeClass].GetMethods().Name
[ParsedLogFile].GetMethods().Name
####################################################################################################
#region Measures
#Measure LogFileParser
Measure-Command -Expression {
$filepath = 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser\'
Set-Location -Path 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser\'
# Dot Sourcing
. '.\LogFileParser\LogFileParser.ps1'
# loading complete directory recursive
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\CBS\cbs.log")
}
#OLD
Measure-Command -Expression {
$filepath = 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser\'
Set-Location -Path 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser\'
# Dot Sourcing
. '.\LogFileParser_OLD\LogFileParser.ps1'
# loading complete directory recursive
$newLogParser = [LogFileParser]::new("$filepath\DemoLogs\CBS\cbs.log")
}
Measure-Command -Expression {
# loading complete directory recursive
$t = (Get-Content -Path "$filepath\DemoLogs\CBS\cbs.log" -ReadCount 1000).Split([Environment]::NewLine)
}
Measure-Command -Expression {
# loading complete directory recursive
$t = (Get-Content -Path "$filepath\DemoLogs\CBS\cbs.log")
}
Measure-Command -Expression {
$filepath = 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser'
Set-Location -Path 'C:\OneDrive\Weiteres\PSConfAsia - 2017\PowerShell Classes - Onhands with the example LogFileParser'
# Dot Sourcing
. '.\LogFileParser\Read-WindowsUpdateLog.ps1'
# loading complete directory recursive
$newLogParser = Read-WindowsUpdateLog -Path "$filepath\DemoLogs\WindowsUpdateLog\WindowsUpdate.log"
}
#endregion
#region LogFileTypeClasses
#Example add additional LogFileClass
$exampleClass = [LogFileTypeClass]::new()
$exampleClass.LogFileType = 'Example'
$exampleClass.Description = 'Example description'
$exampleClass.RegExString = '(?<All>.*)'
$exampleClass.LogFiles = ('example.log', 'example*.log')
$exampleClass.LocationsLogFiles = ('c:\Temp\example.log', 'C:\example.log')
#UNCOMMENT# ($this.LoadedClasses).Add($exampleClass)
return
####################################################################################################
#Creates the classes for the logfiles and exports them
$newLogFileTypeClasses = [LogFileTypeClasses]::new()
$newLogFileTypeClasses | Select-Object -ExpandProperty LoadedClasses
Export-Clixml -InputObject $newLogFileTypeClasses -Path "$filepath\LogFileParser\Classes.xml"
#Import to prove classes
$classes = Import-Clixml -Path "$filepath\LogFileParser\Classes.xml"
$classes | Select-Object -ExpandProperty LoadedClasses
$newLogFileTypeClasses.LoadedClasses.LogFileType
#Loading a specific file with own classes
#$newLogParser = [LogFileParser]::new('C:\OneDrive\## Sources\Git\DemoLogs\DISM\dism.log','C:\OneDrive\## Sources\Git\LogFileParser\Classes.xml')
#endregion
####################################################################################################