I would like to calculate an MD5 checksum of some content. How do I do this in PowerShell?
相关问题
- How to Debug/Register a Permanent WMI Event Which
- How can I do variable substitution in a here-strin
- How to use a default value with parameter sets in
- Does powershell have a method_missing()?
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 在vscode如何用code runner打开独立的控制台窗口,以及设置好调试模式时窗口的编码?
- C#调用PowerShell的问题
- EscapeDataString having differing behaviour betwee
- PowerShell Change owner of files and folders
- Command line escaping single quote for PowerShell
- Is there a simple way to pass specific *named* Pow
- How do I access an element with xpath with a names
- How to 'Grant Permissions' Using Azure Act
This is what I use to get a consistent hash value:
This will return an MD5 hash for a file on a remote computer:
Sample for right-click menu option as well:
Here is a pretty print example attempting to verify the SHA256 fingerprint. I downloaded gpg4win v3.0.3 using PowerShell v4 (requires
Get-FileHash
).Download the package from https://www.gpg4win.org/download.html, open PowerShell, grab the hash from the download page, and run:
Output:
If the content is a string:
If the content is a file:
Starting in PowerShell version 4, this is easy to do for files out of the box with the
Get-FileHash
cmdlet:This is certainly preferable since it avoids the problems the first solution offers as identified in the comments (uses a stream, closes it, and supports large files).
There is now a Get-FileHash function which is very handy.
Just change
SHA384
toMD5
.The example is from the official documentation of PowerShell 5.1. The documentation has more examples.