I am trying to figure out how to print a list of filepaths in a folder, along with their accompanying checksum, and the date last modified.
I can get a list of filepaths and checksums:
Get-ChildItem -Recurse | Get-FileHash | Export-Csv -Path C:\Temp\ListOfHashes.csv
I can also get a list of filepaths, checksums and date last-modified:
Get-ChildItem -File -Recurse |
Select DirectoryName,Name,@{N='Version';E={$_.VersionInfo.ProductVersion}},LastWriteTime,Length,@{N='FileHash';E={(Get-FileHash $_).Hash}} | Export-Csv -Path c:\temp\test11.csv
But the weird thing is that the first script (that just prints the hash) has a hash for every file. The second script prints the filepath, date-last modified and hash, but doesn't always include the hash. Does anyone know why?
I figured out what the problem is: it can't write the hash if the file is open. This script, as well as the ones below, all work.
Edit: Philip Fourie's addition is crucial:
Get-ChildItem -File -Recurse |
Select DirectoryName,Name,@{N='Version';E={$_.VersionInfo.ProductVersion}},LastWriteTime,Length,@{N='FileHash'; E={(Get-FileHash -LiteralPath $_.FullName).Hash}} | Export-Csv -Path c:\temp \test789.csv`