export contents of find to csv

  • 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
  • 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

  • I have used export-csv before but not sure where to insert that into the code?

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • used in forensics to determine nightly load record processing... research... not going to load it into another backend...

    Just a quick way to review...

  • Bruin wrote:

    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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • 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