Home > database >  Get files hashes with other attributes in Powershell
Get files hashes with other attributes in Powershell

Time:10-29

I need to get the Date Created, Date Modified alongside the file hash in Powershell, so my idea is to use this command

gci -Recurse | select Name, CreationTime, LastWriteTime and append Get-FileHash either at the end or after the get-ChildItem and before the Select.

The problem, as I analyzed it, that Get-FileHash needs a path so it does not work if placed at the end, and it works but the Select fails if placed before.

Any idea how to solve it and is that the best way to compare dates or should they be converted to some other format.

CodePudding user response:

Use Select-Object with a calculated property - you'll have access to the path via the object piped down from Get-ChildItem:

Get-ChildItem -Recurse -File |Select Name,CreationTime,LastWriteTime,@{Name='SHA256Hash';Expression={(Get-FileHash -LiteralPath $_.FullName).Hash}}
  • Related