从powershell运行veracrypt

时间:2018-09-04 09:07:21

标签: powershell cmd veracrypt

我正在尝试从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”未被识别为内部或外部   命令,

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

我也尝试将命令放在bat文件中并调用它,但是即使运行bat文件可以按预期工作,但似乎挂起却没有做任何事情。

我是Powershell的新手,怀疑我缺少明显的东西。我想念什么?

2 个答案:

答案 0 :(得分:3)

您应该只能够使用调用运算符&直接运行命令,而无需使用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

  

&呼叫接线员

     

运行命令,脚本或脚本块。调用运算符(也称为“调用运算符”)使您可以运行存储在变量中并由字符串表示的命令。因为调用运算符不会解析命令,所以它无法解释命令参数。

答案 1 :(得分:0)

以防万一,另一种最终对我有用的方法:

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