Select-String. How to use multiple pattern conditions?

  • Hello,

    I am trying to parse through a log file searching for lines that contain strings. The below scripts works to pull all line that have "Found file" in it but I can't get it to retrieve conditions on other lines (i.e. "Records IN" & "File copied"). How can I modify the below to pull lines with those characters strings in them as well?

    $path = pushd \\Eldorado\el\Processing\IVR_New\Log

    $files = Dir -filter *.txt | Where-Object { $_.CreationTime -gt (Get-Date).AddDays(-2) }

    ForEach ($file in $files)

    {

    Get-Content $file |

    Select-String -pattern "Found file"|

    Format-Table -property Line

    }

    Thanks,

    Sean

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Try

    Select-String -pattern "Found file", "Records IN", "File copied" |

  • My Dah! So simple... Thanks!

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

  • Just an FYI if you run Get-Help Select-Sting where you see -Pattern <string[]) that [] means -Pattern takes an array. That applies to all items with a <string[]> in the description. Like Get-WmiObject -ComputerName <string[]>.

  • Good FYI and thanks! That will most definitely help me in the future.

    A clever person solves a problem. A wise person avoids it. ~ Einstein
    select cast (0x5365616E204465596F756E67 as varchar(128))

Viewing 5 posts - 1 through 4 (of 4 total)

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