Search code examples
powershellcmdveracrypt

Run veracrypt from powershell


I'm trying to run the following command from a powershell script.

"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

I've tried using

& 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" 

And

$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

What ever i do i get the error:

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

The 'reate' is not a typo, the c from create is actually removed in the error message. I've tried to escape the create, or put in in quotes but it keeps giving me the same error.

I also tried putting the command in a bat file and calling that but that just seems to hang without doing anything even though running the bat file works as expected.

I'm new to powershell and suspect that I'm missing something obvious. What am i missing?


Solution

  • You should just be able to use the call operator & to run the command directly without using 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
    

    From 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.