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.
Add the name to the output from Get-FileHash
with Select-Object
and a calculated property:
dir -recurse |Get-FileHash -Algorithm MD5 |Select-Object Hash,Path,@{Name='Name';Expression={[System.IO.Path]::GetFileName($_.Path)}} |Export-Csv filename.csv
Now you have it all in a single csv