Page 1 of 1

certutil -hashfile of a directory

Posted: 10 Oct 2019 09:41
by docdave78
I'm trying to run certutil on a directory to output the results to a file using a wildcard to identify the files.

the directory is c:/temp/mfiles
the file extensions are .fdf
the hashfile are SHA256

I'm familiar with using the certutil for a single file, but I'm not sure how to do it for a directory, I have 250+ files that I need to run this on. I've tried multiple commands and tried using FOR, but I'm not well versed in dos to get the results.

The command I use for a single file is, certutil -hashfile file1.fdf SHA256>filehash256.txt, which returns the result I need, but I don't know how to employ it for the contents of a directory.

I am unable to download other utilities do to IT restrictions on my computer so this has to be done with built in commands.

Thank you

Re: certutil -hashfile of a directory

Posted: 10 Oct 2019 10:12
by aGerman
I guess it should be either

Code: Select all

for %%i in ("C:\temp\mfiles\*.fdf") do certutil -hashfile "%%~i" SHA256| >"%%~dpni-hash256.txt" findstr /iv "hash certutil"
or

Code: Select all

>"C:\temp\mfiles\filehash256.txt" (for %%i in ("C:\temp\mfiles\*.fdf") do certutil -hashfile "%%~i" SHA256|findstr /iv "certutil")
depending on whether or not you want to have the hashes in separate files.

Steffen

Re: certutil -hashfile of a directory

Posted: 10 Oct 2019 12:19
by docdave78
Steffen,

Thank you, I've copied the command line into my cmd window exactly as you've provided and its giving me an error of:

"%%i was unexpected at this time.

I should have noted that I'm running Windows 10 Enterprise.

Re: certutil -hashfile of a directory

Posted: 10 Oct 2019 12:25
by aGerman
The code was made for a Batch script. In a cmd window things work differently. Use %i rather than %%i and after DO use @certutil rather than certutil.

Steffen

Re: certutil -hashfile of a directory

Posted: 10 Oct 2019 12:27
by dbenham
aGerman gave you code to put in a batch script.
If you run from the command prompt then each %% must be modified to a single %.

You might want to checkout HASHSUM.BAT - It is a batch script that only uses native commands.

The command to generate the hash values for all the files would be:

Code: Select all

hashsum /p c:/temp/mfiles  *.fdf >filehash256.txt
The output would look something like:

Code: Select all

d36007cbb2e33d620234e5c5b3fbfc49244bc56bb4fd7acd32e2365c3fcd512b *file1.fdf
ffa95d3f56558241b6326aa69f9c77079a35a8f9814e5a5d6680ea655ae0ad7c *file2.fdf
ea645e4c2fb343bbc49e27651ab4554f21d4bde6ac3781b6cc24f8a8cc34acbe *file3.fdf
etc.

Dave Benham

Re: certutil -hashfile of a directory

Posted: 10 Oct 2019 14:27
by docdave78
Steffen, Dave,

Thanks for your help. I was able to get it to work with the hashsum.bat link.

Dave