Unable to get output from get-filehash

前端 未结 3 1373
[愿得一人]
[愿得一人] 2020-12-21 10:43

I am looking for a reliable command-line method of getting SHA256 hashes for files in Windows. My understanding is that the way to do this is via Microsoft\'s Get-FileHash

3条回答
  •  旧巷少年郎
    2020-12-21 11:37

    I calculated the hash of all files on a drive and exported them to a .csv by using this:

    Get-ChildItem C: -Recurse |
        Get-FileHash |
        Export-Csv -Path C:\Users\yourname\Documents\Output\hashes.csv -NoTypeInformation
        Import-Csv -Path C:\Users\yourname\Documents\Output\hashes.csv
    

    Why it works (I think):

    Get-ChildItem <--gets everything under your path, in this case C:, and -Recurse gets all the files within folders. You can add limitations if needed.

    Get-FileHash <--after you've said get these files, you're saying calculate the hashes

    Export-Csv <--says, we're sending your hashes out as comma separated values file, which is crazy helpful, and -Path says put it HERE, -NoTypeInformation just removes the #TYPE row from the top of the .csv file, and versions of PowerShell before 6 need this.

    Import-Csv <--says, bring that data into the file at this -Path

    Be sure to have the .csv file created in that location before you run the script. The script won't create the container for you. There's no need to clear the data from the .csv file between runs, it clears itself.

    I'm not really a programmer, hence the annoyingly lengthy explanation. Hope it helps others. Wouldn't have figured it out without Stack Overflow forums! Thanks everyone!!

提交回复
热议问题