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)

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

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

  • Any ideas how I can capture the actual line for the string capture and where to place inside of script.. I know about export-csv, but can't seem to get the actual hit in the string search to dump.

    Thanks.

  • google has lots of examples - so which ones did you try and what was the result.

    its not like YOU trying it will cause any issues - and you will eventually learn something with that exercise.

  • So write after the

     

    ForEach($String in $Strings)

    I have been displaying variables to see which one holds my data that I want to dump to export-csv...

     

  • It seems that you're not trying the suggestions here with any great application.

    Instead, you appear to be waiting for someone here to write the solution for you. Unless you can show that you are really applying yourself, I suspect that the help here will dry up for you. In fact, that is already happening.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply