gpt4 book ai didi

powershell - 从 powershell 运行 veracrypt

转载 作者:行者123 更新时间:2023-12-02 03:29:45 28 4
gpt4 key购买 nike

我正在尝试从 powershell 脚本运行以下命令。

"C:\Program Files\VeraCrypt\VeraCrypt Format-x86.exe" /create "C:\test veracrypt file.hc" /password alongpasswordisagoodpassword /hash sha512 /encryption serpent /filesystem NTFS /size 100G /dynamic /force /silent

我尝试过使用

& cmd.exe ""C:\Program Files\VeraCrypt\VeraCrypt Format-x86.exe" /create "C:\test veracrypt file.hc" /password alongpasswordisagoodpassword /hash sha512 /encryption serpent /filesystem NTFS /size 100G /dynamic /force /silent" 

$command = @'
& cmd.exe ""C:\Program Files\VeraCrypt\VeraCrypt Format-x86.exe" /create "C:\test veracrypt file.hc" /password
alongpasswordisagoodpassword /hash sha512 /encryption serpent /filesystem NTFS /size 100G /dynamic /force /silent"
'@
Invoke-Expression -Command:$command

无论我做什么,我都会收到错误:

cmd.exe : 'reate' is not recognized as an internal or external command,

“reate”不是拼写错误,create 中的 c 实际上已在错误消息中删除。我试图逃避创建,或者用引号引起来,但它一直给我同样的错误。

我还尝试将命令放入 bat 文件中并调用它,但即使运行 bat 文件按预期工作,它似乎也挂起而不执行任何操作。

我是 powershell 新手,怀疑我遗漏了一些明显的东西。我错过了什么?

最佳答案

您应该能够使用调用运算符 & 直接运行命令,而无需使用 cmd:

& "C:\Program Files\VeraCrypt\VeraCrypt Format-x86.exe" /create "C:\test veracrypt file.hc" /password alongpasswordisagoodpassword /hash sha512 /encryption serpent /filesystem NTFS /size 100G /dynamic /force /silent

来自about_operators

& Call operator

Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings. Because the call operator does not parse the command, it cannot interpret command parameters.

关于powershell - 从 powershell 运行 veracrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162714/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com