Powershell finding string and date

Dear Expert

dir c:\ -I *.* -R | Select-String 45kfhh

I am trying to search in c:\ with a Select-String 45kfhh, however this takes forever. I know the file that have string; 45kfhh is created 10 days ago, how do I add option of datum here? however if you know its better to use the Get-ChildItems is better then how is the script command like then?

Thanks Wei
LVL 1
WeTiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Try findstr:

findstr /s /i (if case-insensitive) /m /p "45kfhh"
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
I would try this, if it's a directory

Get-ChildItem  C:\  -File -Recurse -Directory  -filter{Name -match  "45kff"}

Open in new window


or this if it's a file:
Get-ChildItem  C:\  -File -Include "*45kff*" -Recurse -File

Open in new window


Maybe with a little help, like what is the extension of the file, would be helpful.
And of course it will take forever, it has to go over the whole C: drive searching for that, maybe you could give a more accurate path than just C: to reduce time because I'm pretty sure it shouldn't be on C:\windows, it could be on C:\users? or something like that.
0
WeTiAuthor Commented:
Get-ChildItem  C:\  -File -Recurse -Directory  -filter{Name -match  "45kff"} this will only match Directory name right? Not what i wanted.  Get-ChildItem  C:\  -File -Include "*45kff*" -Recurse -File This only match name file, nope not what i wanted.

I want Powershell to search inside the file string: 45kff, like there is a log file in a directory that have a text string inside the log file: 45kff, there is like 4000 log files, and i cant open all of them and check. I want to find that file that have 45kff text string in it, and to speed up the process I want to spec the time, like: date from 10 days ago and other ignore.
0
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
YEs -directory will search directories. -file will search files. that's why I did it both ways because Idk what are you looking for if it was a directory name or a file name.
0
WeTiAuthor Commented:
I'm looking for a text inside a log file, there is a directory name: c:\log\ inside this got 5000 logs files, with name: 111111.log, 22222.log, etc. if you open those log files there is a text "45kff" in one of those log files. I'm trying to find that. dir c:\ -I *.* -R | Select-String 45kfhh command does the job, however it takes too long time. I know the file was created around 10 days ago, so I want script only search those files which created 10 days ago and inside with a text string: 45kff.
0
Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
Select-String -Path C:\Log\*.log -pattern 45kfhh

Open in new window


or

Dir C:\log  -I *.log -R | Select-string 45kfhh

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyCommented:
...or, the findstr example I posted above... ;^)
0
WeTiAuthor Commented:
Yes, then it will search everything inside that folder, I want to be more specific like, date or time... If you don't write any date, it will go through every logs, which took 1-2 days.
0
WeTiAuthor Commented:
Just tried Select-String -Path C:\Log\*.log -pattern  this went faster, however I need to understand, why it went faster tho.
0
WeTiAuthor Commented:
Thanks for the help, Select String helped.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.