Seems like this should be simple enough.
get-childitem -path "E:\Test 1" -Recurse -File | foreach-Object { $fsize=(get-Item $_.FullName).Length ; $hash=(get-FileHash $_.Fullname -Algorithm MD5 | Select-Object Hash,Path ); write-host $fsize $hash }
This will result in an output like this:
18 @{Hash=2FC4C77B6792F3DA856E77486F849105; Path=E:\Test 1\file 1.txt}
Now I just want to display file size, file hash, file path.
I know I can use -ExpandProperty for a single property but how do I expand for both hash and path?
This works fine for just the Hash:
get-childitem -path "E:\Test 1" -Recurse -File | foreach-Object { $fsize=(get-Item $_.FullName).Length ; $hash=(get-FileHash $_.Fullname -Algorithm MD5 | Select-Object Hash,Path -ExpandProperty Hash); write-host $fsize $hash }
which results in:
18 2FC4C77B6792F3DA856E77486F849105
But you can't use -ExpandProperty with multiple values
get-childitem -path "E:\Test 1" -Recurse -File | foreach-Object { $fsize=(get-Item $_.FullName).Length ; $hash=(get-FileHash $_.Fullname -Algorithm MD5 | Select-Object Hash,Path -ExpandProperty Hash,Path); write-host $fsize $hash }
How can I extract the Path as well so it displays like this?
18 2FC4C77B6792F3DA856E77486F849105 E:\Test 1\file 1.txt
Thanks in advance for your patience with me and assistance.
You don't need to call
Get-Itemto retrieve the file'sLength- you already have the exact same information fromGet-ChildItem.In order to get multiple property values from
Get-FileHashattached to each file without having to callGet-FileHashmultiple times for each, you can useSelect-Objecttwice in a row to first extract the output fromGet-FileHash, and then use-ExpandPropertyagainst that:The
Pathvalue you get fromGet-FileHashisn't really necessary either - you already have the same information from theFullNameproperty on the file info object and can do just a single pass withSelect-Object: