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

Try findstr:

findstr /s /i (if case-insensitive) /m /p "45kfhh"
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
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.
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.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
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.
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.
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
Select-String -Path C:\Log\*.log -pattern 45kfhh

Open in new window


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

Open in new window

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
...or, the findstr example I posted above... ;^)
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.
WeTiAuthor Commented:
Just tried Select-String -Path C:\Log\*.log -pattern  this went faster, however I need to understand, why it went faster tho.
WeTiAuthor Commented:
Thanks for the help, Select String helped.
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

From novice to tech pro — start learning today.