繁体   English   中英

从批处理文件运行时,PowerShell 中的 Get-Filehash SHA256 加密会删除最后 4 位数字

[英]Get-Filehash SHA256 encryption in powershell drops last 4 digits when run from a batch file

但是,当我从 powershell 运行 Get-Filehash 时,它可以工作:

当我从批处理文件运行它时,它会删除最后 4 位数字。

powershell.exe -NoProfile -ExecutionPolicy -Command "Get-FileHash filename.edi -Algorithm SHA256 | Out-File c:\app\testfileout.txt"
 Algorithm Hash --------- ---- SHA256 3EFEC59BFB0573061C5CD2F72A684663B60CA3D0D91C67CBDBBE366A59FE...

如何让输出文件仅是:

 3EFEC59BFB0573061C5CD2F72A684663B60CA3D0D91C67CBDBBE366A59FE4A8F

当我运行此命令时,它为我提供了 Powershell 中的完整哈希值:

Get-FileHash filename.edi -Algorithm SHA256 | Out-File c:\app\testfileout.txt

我只需要没有标题的哈希值以及最后 4 位数字。

有没有人有一个已经这样做的脚本?

它返回一个对象,因此您需要做的就是使用 Select-Object 和 ExpandProperty:

powershell.exe -NoProfile -ExecutionPolicy -Command "Get-FileHash filename.edi -Algorithm SHA256 | Select-Object -ExpandProperty Hash | Out-File c:\app\testfileout.txt"

或通过点符号引用对象属性:

powershell.exe -NoProfile -ExecutionPolicy -Command "(Get-FileHash filename.edi -Algorithm SHA256).Hash | Out-File c:\app\testfileout.txt"

使用纯 ,您可以这样做:

cmd /V /C for /F "tokens=*" %H in ('certutil -hashfile "filename.edi" SHA256 ^^^| find /V ":"') do @(set "HASH=%H" ^& echo !HASH: =!) > "C:\app\testfileout.txt"

,它可能如下所示:

setlocal EnableDelayedExpansion
for /F "tokens=*" %%H in ('
    certutil -hashfile "filename.edi" SHA256 ^| find /V ":"
') do @(
    set "HASH=%%H" & echo !HASH: =!
) > "C:\app\testfileout.txt"
endlocal

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM