June 22, 2022 at 3:27 pm
This gives me a recap of what I'm searching for, how can I dump individual found strings to export csv?
thx
# Strings to parse the log for
$Strings = "Number of Designs needing to be processed :"
# Folder of logs to parse
$LogFolder = "C:\miscjunk"
# Log file extension
$LogExtension = ".log"
# Finding all logs in the folder (add -Recurse to get all logs in sub folders too)
$Logs = Get-ChildItem -Path $LogFolder | Where {$_.Name -match $LogExtension} | Select Name,FullName
# Counting log files
$LogCount = $Logs | Measure | Select -ExpandProperty Count
$LogCounter = 0
# Creating array to store results
$LogResults = [System.Collections.ArrayList]@()
# Parsing each log
ForEach ($Log in $Logs)
{
$LogCounter ++
# Setting variables
$LogName = $Log.Name
$LogPath = $Log.FullName
# Output to host
"ProcessingLog: $LogCounter/$LogCount
File: $LogName"
# Loading the log content
$LogContent = Get-Content $LogPath
# For each string to match, checking log
ForEach($String in $Strings)
{
# Finding matches
$Matches = $LogContent | Select-String -Pattern $String | Measure | Select -ExpandProperty Count
# Selecting first string found
$StringFound = $LogContent | Select-String -Pattern $String | Select -First 1
# Adding to array
$LogResult = New-Object PSObject
$LogResult | Add-Member -MemberType NoteProperty -Name "String" -Value $String
$LogResult | Add-Member -MemberType NoteProperty -Name "Matches" -Value $Matches
$LogResult | Add-Member -MemberType NoteProperty -Name "Error" -Value $StringFound
$LogResult | Add-Member -MemberType NoteProperty -Name "Log" -Value $LogName
$LogResult | Add-Member -MemberType NoteProperty -Name "Path" -Value $LogPath
$LogResults.Add($LogResult) | Out-Null
}
# End of for each log file below
}
# End of for each log file above
#
# Showing result
$LogResults | Sort Matches -Desc | Format-Table -AutoSize
June 22, 2022 at 5:31 pm
you are aware that this has been answered rather often and that what you need can be found with a simple google search - not to speak on the old thing called Manuals and Help within Powershell ISE itself
June 22, 2022 at 5:34 pm
I have used export-csv before but not sure where to insert that into the code?
June 22, 2022 at 5:36 pm
I can't help on the PowerShell but, even if I could, I'd still ask the following question...
How will the resulting CSV files be used and by what?
--Jeff Moden
June 22, 2022 at 6:23 pm
used in forensics to determine nightly load record processing... research... not going to load it into another backend...
Just a quick way to review...
June 22, 2022 at 8:19 pm
used in forensics to determine nightly load record processing... research... not going to load it into another backend...
Just a quick way to review...
Interesting. In that case, I WOULD be tempted to load them into a table for analysis. Thanks, Bruin.
--Jeff Moden
June 23, 2022 at 12:57 am
Thanks Jeff... have tried a few display in script to see where I could inject the export-csv but not pulling the info from serach
Thx.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply