July 2018
Beginner
552 pages
13h 18m
English
Another way to parse log files is to use the ConvertFrom-String cmdlet, with which you can create a pattern file. You can easily extract two lines from your log file and replace the desired values with {%Name%:%Value%}. The following example demonstrates this approach for the dism.log log file:
#Reading content of log file - last 50 lines$targetData = Get-Content C:\Windows\Logs\DISM\dism.log -Tail 50#2 example lines of code - replaced pattern values with {%Name%:%Value%}$TemplateContent = @'{Date*:2015-12-15} {Time:21:04:26}, {Level:Info} {Component:DISM} API: PID={PID:1472} TID={TID:5760} {Info:DismApi.dll: - DismInitializeInternal}{Date*:2015-12-15} {Time:21:04:26}, {Level:Info} {Component:DISM} API: PID={PID:1472} ...
Read now
Unlock full access