1

I am struggling to combine the output from two commands into a single CSV / TXT file.

The first command is to recursively search a folder and create an MD5 number for each document. This is then exported to a CSV file that includes the full path.

dir -recurse | Get-FileHash -Algorithm MD5 | Export-CSV MD5ofFolder.csv

The second command is to retrieve all the filenames within the folder (and sub-folders) WITHOUT including any pathing:

get-childitem -recurse|foreach {$_.name} > filename.txt

In a perfect world, I would be able to export a single CSV or TXT document that contains the MD5 values, the full path, and the filename (with extension).

I note that my second code string also produces the folder names in the output, which is not desirable. I am able to produce a text output without the folder names, but the code is ugly, and it doesn't do what I want:

dir -recurse | Get-FileHash -Algorithm MD5 | dir -recurse | foreach {$_.name} > filename.txt

I am sure this is a simple problem for someone smarter than me, so any and all help would be appreciated - I am VERY new to PowerShell.

4

1 回答 1

2

将名称添加到Get-FileHashwithSelect-Object和计算属性的输出中:

dir -recurse |Get-FileHash -Algorithm MD5 |Select-Object Hash,Path,@{Name='Name';Expression={[System.IO.Path]::GetFileName($_.Path)}} |Export-Csv filename.csv

现在您将所有内容都保存在一个 csv 中

于 2018-03-20T17:09:07.007 回答