none
filtering errors in a mapp full of textfiles powershell script RRS feed

  • Question

  • Can someone pls give me an easy example on how to find a specific Word, like "error".

    This is an example of how to find an error on 1 file.

    Get-ContentC:\Users\123\Desktop\log\mail.log|Select-Object-First10000|Select-String("Error") |Out-FileC:\Users\1234\Desktop\leave\ouputerror.txt


    Friday, May 24, 2019 8:58 AM

All replies

  • Hi,

    can you please be more specific: Where do you want to find the word? In multiple files simultaneously?

    What is wrong with the example you've posted?

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov


    Friday, May 24, 2019 9:12 AM
  • Use FindStre

    https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr


    Please remember to mark the replies as answers if they help


    Friday, May 24, 2019 9:12 AM
  • I want to find "error" in log files. There is time and date on every folder. you can see down below how it looks like. Inside of these folders there is other folders that are named "mail1" "mail2" on so on.

    2019-05-24 00.00.09

    2019-05-23 00.00.08

    2019-05-22 00.00.05

    2019-05-21 00.00.06

    2019-05-20 00.00.09

    Mail1 Folder is a log that i want to find the "error".

    My example just showed for finding error in 1 log file.

    My English is not that good btw.


    • Edited by Hello11111 Friday, May 24, 2019 2:21 PM
    Friday, May 24, 2019 10:30 AM
  • I want to find "error" in log files. There is time and date on every folder. you can see down below how it looks like. Inside of these folders there is other folders that are named "mail1" "mail2" on so on.

    2019-05-24 00.00.09

    2019-05-23 00.00.08

    2019-05-22 00.00.05

    2019-05-21 00.00.06

    2019-05-20 00.00.09

    Mail1 Folder is a log that i want to find the "error".

    My example just showed for finding error in 1 log file.

    My English is not that good btw.


    Folder or file? Is mail1 a log file name?

    If so, please try the script below:

    $directory=Get-ChildItem -Path C:\test\ | Where-Object {$_.name -match '(\d+)-(\d+)-(\d+) (\d+).(\d+).(\d+)'}
     foreach($dir in $directory)
     {
       Get-ChildItem "$($dir.fullname)\mail*.log"| %{Get-Content $_.fullname | Select-String "error" | Out-File c:\test\user.txt -Append }
     }

    This script will help you get the date time format folders and get content of mail logs error information.

    Best regards,

    Lee


    Just do it.

    Monday, May 27, 2019 7:25 AM
    Moderator