<tutorialjinni.com/>

PowerShell Get Hash Of All Files In Directory

Posted Under: PowerShell, Shell, Snippets, Tutorials, Windows on Sep 4, 2022
PowerShell Get Hash Of All Files In Directory
Code Snippet to traverse a folder and calculate hash of each file. Seven type of hashing algorithm are available including popular hashing algorithms, MD5 and SHA. It can also traverse recursively with Recurse switch. Script has the ability to generate its output as a comma separated values file for easy reporting and management.
foreach($file in Get-ChildItem "PATH\TO\FOLDER" -Recurse){
    if (-not $file.PSIsContainer){# Calculate hash only if Path is a File
        $hash= (Get-FileHash -Path $file.PSPath -Algorithm  SHA1);
        #Supported Hash Alogrithm SHA1 | SHA256 | SHA384 | SHA512 | MACTripleDES | MD5 | RIPEMD160
        Write-Output $hash
        #To Export output as CSV
        #$hash | Export-Csv -PATH "FILE_NAME.CSV" -Append;
    }
}






imgae