如何将 Windows 文件夹内每个文件的哈希值 (SHA-256 和 MD5) 导出为 CSV?

发布于 2025-01-10 04:27:12 字数 354 浏览 0 评论 0原文

我从客户端接收文件,即使在处理这些文件之后,我也需要确保这些文件是健康的。 我要提防的是可能篡改已处理文件的情况。 发送缺少信息的文件时可能会发生客户错误,并且客户想要编辑原始文件以表明该信息存在。 这就是为什么我想到用接收目录中这些文件的哈希值生成一份报告。 尽管我不会说英语,但我努力让一切变得更加清晰易懂。

场景 1: 我有一个包含多个文本文件的目录,我需要将每个文件中的 SHA-256 和 MD5 哈希计算导出到某个位置的 CSV。

场景 2: 我有一个目录,其中包含几个带有客户名称的子文件夹,以及这些客户中的其他子文件夹。如何提取 SHA-256 和 SHA-256这些目录和子目录中所有文件的 MD5 哈希值?

I receive files from the client and I need to make sure those files are healthy even after I process these files.
What I want to beware of is a situation of possible tampering with already processed files.
A customer error may occur for sending files with missing information and the customer wants to edit the original file to say the information was there.
That's why I had the idea of ​​producing a report with the hash of these files that are in the reception directory.
I tried hard to make everything clearer and more intelligible, even though I didn't speak English.

Scene 1:
I have a directory with several text files and I need to export the SHA-256 and MD5 hash calculations from each file to a CSV somewhere.

Scene 2:
I have a directory with several subfolders with customer names and within these customers, other subfolders. How to extract SHA-256 & MD5 Hash from all files in these directories and subdirectories?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2025-01-17 04:27:12

类似下面的内容应该可以帮助您开始。这会找到当前目录(不包括子目录)内每个文件的 SHA256 哈希值

Get-ChildItem | Get-FileHash | Export-CSV -Path "C:\Temp\summary.csv"  
PS C:\Users\Jan\Dropbox\py\advent_of_code> cat "C:\Temp\summary.csv"
#TYPE Microsoft.Powershell.Utility.FileHash
"Algorithm","Hash","Path"
"SHA256","8E8FF02948E62C54EF782373500CD0D97B8A2DA0F1655A6134B37284CF5BCE79","C:\Users\Jan\Dropbox\py\advent_of_code\20191201.in"
"SHA256","63E68322B7E8131CDDEFB77492EC7E1B8B8C46696772CE561850C854E4E8B6EA","C:\Users\Jan\Dropbox\py\advent_of_code\20191201.py"
"SHA256","FFF1D3F7F7FBDDC4CDC90E123D9BC7B0B7A450DC28F3A4F2D786701B4A9B279D","C:\Users\Jan\Dropbox\py\advent_of_code\20191204.py"
"SHA256","DE3662893F2779446AFC78B20E63F5250826D5F52206E5718E1A2713F876941E","C:\Users\Jan\Dropbox\py\advent_of_code\20191206.in"
"SHA256","B9381E11A442DDC8CF802F337F0487E9269800B145106FFDDB0E6472D8C6F129","C:\Users\Jan\Dropbox\py\advent_of_code\20191206.py"    

如果您确实需要 SHA256 和 MD5:

$h = @(Get-ChildItem | Get-FileHash)
$h2 = ($h | Get-Item | Get-FileHash -Algorithm MD5)  
for ($i=0; $i -lt $h.Length; $i++) { 
    $h[$i] = [PSCustomObject]@{Path=$h[$i].Path; SHA256=$h[$i].Hash; MD5=$h2[$i].Hash} 
}
$h | Export-Csv "C:\Temp\expo.txt" 
PS C:\Users\Jan\Dropbox\py\advent_of_code> cat "C:\Temp\expo.txt"
#TYPE System.Management.Automation.PSCustomObject
"Path","SHA256","MD5"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191201.in","8E8FF02948E62C54EF782373500CD0D97B8A2DA0F1655A6134B37284CF5BCE79","11689BA3058C306DAA3651562621BE20"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191201.py","63E68322B7E8131CDDEFB77492EC7E1B8B8C46696772CE561850C854E4E8B6EA","3F50E29C797ED4BD65122F8DA1208D4D"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191204.py","FFF1D3F7F7FBDDC4CDC90E123D9BC7B0B7A450DC28F3A4F2D786701B4A9B279D","41094A3E067669F46C965D0E34EA5CA6"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191206.in","DE3662893F2779446AFC78B20E63F5250826D5F52206E5718E1A2713F876941E","1A7571873E6B9430A2BFD846CA0B8AB7"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191206.py","B9381E11A442DDC8CF802F337F0487E9269800B145106FFDDB0E6472D8C6F129","0CBB058D315944B7B5183E33FC780A4D" 

Something like the following should get you started. This finds the SHA256 hash for every file inside the current directory (not including subdirectories)

Get-ChildItem | Get-FileHash | Export-CSV -Path "C:\Temp\summary.csv"  
PS C:\Users\Jan\Dropbox\py\advent_of_code> cat "C:\Temp\summary.csv"
#TYPE Microsoft.Powershell.Utility.FileHash
"Algorithm","Hash","Path"
"SHA256","8E8FF02948E62C54EF782373500CD0D97B8A2DA0F1655A6134B37284CF5BCE79","C:\Users\Jan\Dropbox\py\advent_of_code\20191201.in"
"SHA256","63E68322B7E8131CDDEFB77492EC7E1B8B8C46696772CE561850C854E4E8B6EA","C:\Users\Jan\Dropbox\py\advent_of_code\20191201.py"
"SHA256","FFF1D3F7F7FBDDC4CDC90E123D9BC7B0B7A450DC28F3A4F2D786701B4A9B279D","C:\Users\Jan\Dropbox\py\advent_of_code\20191204.py"
"SHA256","DE3662893F2779446AFC78B20E63F5250826D5F52206E5718E1A2713F876941E","C:\Users\Jan\Dropbox\py\advent_of_code\20191206.in"
"SHA256","B9381E11A442DDC8CF802F337F0487E9269800B145106FFDDB0E6472D8C6F129","C:\Users\Jan\Dropbox\py\advent_of_code\20191206.py"    

If you really need both SHA256 and MD5:

$h = @(Get-ChildItem | Get-FileHash)
$h2 = ($h | Get-Item | Get-FileHash -Algorithm MD5)  
for ($i=0; $i -lt $h.Length; $i++) { 
    $h[$i] = [PSCustomObject]@{Path=$h[$i].Path; SHA256=$h[$i].Hash; MD5=$h2[$i].Hash} 
}
$h | Export-Csv "C:\Temp\expo.txt" 
PS C:\Users\Jan\Dropbox\py\advent_of_code> cat "C:\Temp\expo.txt"
#TYPE System.Management.Automation.PSCustomObject
"Path","SHA256","MD5"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191201.in","8E8FF02948E62C54EF782373500CD0D97B8A2DA0F1655A6134B37284CF5BCE79","11689BA3058C306DAA3651562621BE20"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191201.py","63E68322B7E8131CDDEFB77492EC7E1B8B8C46696772CE561850C854E4E8B6EA","3F50E29C797ED4BD65122F8DA1208D4D"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191204.py","FFF1D3F7F7FBDDC4CDC90E123D9BC7B0B7A450DC28F3A4F2D786701B4A9B279D","41094A3E067669F46C965D0E34EA5CA6"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191206.in","DE3662893F2779446AFC78B20E63F5250826D5F52206E5718E1A2713F876941E","1A7571873E6B9430A2BFD846CA0B8AB7"
"C:\Users\Jan\Dropbox\py\advent_of_code\20191206.py","B9381E11A442DDC8CF802F337F0487E9269800B145106FFDDB0E6472D8C6F129","0CBB058D315944B7B5183E33FC780A4D" 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文