February 16, 2012 at 1:14 pm
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))
February 16, 2012 at 1:28 pm
Try
Select-String -pattern "Found file", "Records IN", "File copied" |
February 16, 2012 at 2:46 pm
My Dah! So simple... Thanks!
A clever person solves a problem. A wise person avoids it. ~ Einstein
select cast (0x5365616E204465596F756E67 as varchar(128))
February 16, 2012 at 4:06 pm
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[]>.
February 16, 2012 at 6:26 pm
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 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy