I have multiple log files. I need to :
- Parse all log files in a folder
- Extract lines from the log file which relate to the user login info
- Create a consolidated file with only login date and user-id
... using PowerShell. Any help will be greatly appreciated.
Sample of files to the folder
log11-1.log
log11-2.log
log11-3.log
sample of text within each log file
11-1-2019 00:00:14.417 uagdouafiaf uaihoahfoiafioaf user='jhni' uiufqsnisannaso;ngisndoindgingdn
11-1-2019 00:00:14.419 acosn;onciswnonioqecio;mqo;imicd,m;co,co,eq,cc,oecmionecuieqqiq'
11-1-2019 00:00:16.417 aisfoncaonzoicnaioncioano,co,eq,cc,oecmionecuieqqiq'
11-1-2019 00:00:17.417 uagdouafiaf uaihoahfoiafioaf user='thmi' uiufqsnisannaso;ngisndoindgingdn
Expected Output
11-1-2019 00:00:14.417 jhni
11-1-2019 00:00:17.417 thmi
Currently i have below code
$path = "C:\Logs"
$Text = "user"
$Results = "C:\Logs\login.txt"
$files = Get-ChildItem $path -recurse -Include *.log
foreach ($file in $files) {
Get-Content $file | Select-String -Pattern $Text | select -Expand Line | Out-File $Results -Append
}