Get hash of all files in a folder and export it to txt file using PowerShell. Run this command in PowerShell and remember to change the folder path.
- Talfor
- Jul 24
- 1 min read
During incident response process, it is important to quickly collect hash value of all files in a folder. Use PowerShell as administrator and use this command.
param ( $folders = @(“C:\path\folder_name”) ) $allFiles = foreach($folder in $folders) { Get-Childitem -path $folder -recurse | select FullName,Name,Length | foreach { hash = Get-FileHash -Algorithm MD5.FullName add-member -InputObject $ -NotePropertyName Hash -NotePropertyValue $hash.Hash add-member -InputObject $_ -NotePropertyName RelativePath -NotePropertyValue $_.FullName.Replace($folder, ‘’) -PassThru } } $allFiles | select -First 10 | ft RelativePath, Hash >> C:\path\folder_name\output_hash.txt