Save md5 hash for file using powershell

When i use:

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

output

 Hash ---- 1231234567890ABCDEF4567890ABCDEF 

When i use:

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

File contents:

 Hash ---- 1231234567890ABCDEF4567890ABCDEF 

I want only MD5 in the content. How to implement this?

0
source share
1 answer

Use -ExpandProperty in your choice.

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

Or like that

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

In a loop, it might look something like this (the hash for "file.ext" will fall into a file called "file.ext.md5".

 Get-ChildItem * -Include '*.ext' | foreach { (Get-FileHash $_ -Algorithm MD5).Hash > "$($_.Name).md5" } 
+2
source

All Articles