Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从批处理文件运行时,powershell中的Get-Filehash SHA256加密会删除最后4位数字_Powershell_Encryption_Cmd_Sha256_Batch File - Fatal编程技术网

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

从批处理文件运行时,powershell中的Get-Filehash SHA256加密会删除最后4位数字,powershell,encryption,cmd,sha256,batch-file,Powershell,Encryption,Cmd,Sha256,Batch File,当我从powershell运行Get-Filehash时,它可以工作,但是: 当我从批处理文件运行它时,它会删除最后4位数字 powershell.exe -NoProfile -ExecutionPolicy -Command "Get-FileHash filename.edi -Algorithm SHA256 | Out-File c:\app\testfileout.txt" 如何使输出文件仅为: 当我运行此命令时,它将提供Powershell中的完整哈希: Get-FileHash

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

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

powershell.exe -NoProfile -ExecutionPolicy -Command "Get-FileHash filename.edi -Algorithm SHA256 | Out-File c:\app\testfileout.txt"
如何使输出文件仅为:

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

Get-FileHash filename.edi -Algorithm SHA256 | Out-File c:\app\testfileout.txt
我需要的只是没有标题的散列以及最后4位数字

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

是否有人已经有了执行此操作的脚本?

它会返回一个对象,因此您只需将选择对象与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"
使用pure,您可以这样做:

cmd/V/C for/F“tokens=*%H in('certutil-hashfile“filename.edi”SHA256^^^ | find/V:“'))do@(设置“HASH=%H”^&echo!HASH:=!)>C:\app\testfileout.txt
在a中,它可能如下所示:

setlocal EnableDelayedExpansion
对于/F“令牌=*”%%H('
certutil-hashfile“filename.edi”SHA256^ | find/V:“
""做"@(
设置“HASH=%%H”&echo!HASH:=!
)>“C:\app\testfileout.txt”
端部

cmd.exe,不管外观如何,都不是DOS。
powershell.exe -NoProfile -ExecutionPolicy -Command "(Get-FileHash filename.edi -Algorithm SHA256).Hash | Out-File c:\app\testfileout.txt"