3

When I use:

Get-FileHash file.ext -Algorithm MD5 |select Hash

the output is

Hash                                               
----
1231234567890ABCDEF4567890ABCDEF

When I use:

Get-FileHash file.ext -Algorithm MD5 |select Hash >file.md5

File content is:

Hash                                               
----
1231234567890ABCDEF4567890ABCDEF

I want in content only MD5 sum. How to implement that?

1 Answer 1

5

Use -ExpandProperty in your select.

Get-FileHash file.ext -Algorithm MD5 | select -ExpandProperty Hash >file.md5

Or like this

(Get-FileHash file.ext -Algorithm MD5).Hash > file.md5

In a loop it could look something like this (hash for "file.ext" would end up in a file called "file.ext.md5".

Get-ChildItem * -Include '*.ext' | foreach { (Get-FileHash $_ -Algorithm MD5).Hash > "$($_.Name).md5" }
Sign up to request clarification or add additional context in comments.

3 Comments

Your Select-Object solution is better, but I wanted to mention you can also do this with Foreach-Object. Get-FileHash file.ext -Algorithm MD5 | % Hash > file.md5
When I use it in foreach loop that goes throuth list of files basenames [Get-ChildItem . -Include '.ext' |select BaseName] (Get-FileHash ($list_name + '.ext') -Algorithm MD5).Hash > ($list_name + '.ext.md5') it doesn't work.
When you've got a list of filenames, use the select version, or the % Hash line I put above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.