Link to home
Start Free TrialLog in
Avatar of WeTi
WeTi

asked on

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
Avatar of sirbounty
sirbounty
Flag of United States of America image

Try findstr:

findstr /s /i (if case-insensitive) /m /p "45kfhh"
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.
Avatar of WeTi
WeTi

ASKER

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.
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.
Avatar of WeTi

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WeTi

ASKER

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.
Avatar of WeTi

ASKER

Just tried Select-String -Path C:\Log\*.log -pattern  this went faster, however I need to understand, why it went faster tho.
Avatar of WeTi

ASKER

Thanks for the help, Select String helped.