0

I need to find any file across the entire file system that includes a string of text featuring between 30 & 40 consecutive characters only (i.e. it should match a md5 hash and not a sha512 hash for instance) and where the charset is lowercase letters (a-z) or uppercase letters (A-Z) or numbers(0-9).

findstr /S /i /R /m "^[a-z0-9]{30,40}$" *.txt

I tried with the above and the output was as follows (I just wanted to check text files first to see if I could find the values I'm looking for);

FINDSTR: Out of memory

I looked at https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr for guidance but not got much experience with the Windows command-line. I know the range I used above {30,40} isn't really referred to within the docs for findstrand that's the part I'm really struggling with.

Note that I don't have to use findstrand can use other in-built Windows utilities or PowerShell just as long as its executed via the command-line is only requirement.

3
  • how do you intend to deal with files that are not plain text? something like an MSWrod file might not be readable without an extra helper util. – Lee_Dailey Apr 11 '20 at 1:19
  • for the basic idea, take a look at Get-ChildItem to get the files, and then Select-String to find the matching content. – Lee_Dailey Apr 11 '20 at 1:20
  • Well, some line sample where you intent find this string will be useful if you consent to post in your question, I think.... – It Wasn't Me Apr 19 '20 at 20:49
0

The PowerShell version of what you re after is using the Get-ChildItem and Get-Content cmdlet using either Select-String or RegEx as you are using now.

# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-Content).Parameters
(Get-Command -Name Get-Content).Parameters.Keys
Get-help -Name Get-Content -Examples
Get-help -Name Get-Content -Full
Get-help -Name Get-Content -Online

There are many examples all over the web and full script that you can use as-is, or tweak for global search and string selection.

Even modules in Microsoft's powershellgallery.com directly accessible in your PowerShell sessions.

Find-Module -Name '*string*' | 
Format-Table -AutoSize

Version Name                                             Repository Description                                                                                                            
------- ----                                             ---------- -----------                                                                                                            
1.7.2   Find-String                                      PSGallery  Find-String is a PowerShell script whose purpose is to emulate grep and/or ack by providing searching over text files. 
...
1.1     Join-Strings                                     PSGallery  Provides a pipeline-ending cmdlet that will join all strings from the preceding pipeline.                              
2.0     StringManager                                    PSGallery  String manager tool to work with strings in multiple ways.                                                             
1.0.0.0 strings                                          PSGallery  Search strings in binary files. 

As far as matching string length and hash matching, there is no way to do this with one-liners, you are going to have to write more code for comparison efforts.

And remember this is only when you are dealing with text files. Going after, Officer files or pdf requires more effort and 3rdP addons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.