0

I am trying to write a Powershell script and I am a novice at scripting. I have pieced together code I have found and so far the script runs. I want to run the following command:

wsl veracrypt -tc -m=nokernelcrypto /dev/sdc1

Doing it I am asked:

Enter mount directory [default]:

At this point I need to enter:

/mnt/wsl/PHYSICALDRIVE1

My question is how in my script can I pass the argument /mnt/wsl/PHYSICALDRIVE1 so it is entered without my input?

<#
# .SYNOPSIS
#  A Powershell script to help mount a Veracrypt encrypted drive through Windows Sub-system for Linux.
#>

#  This checks if a mount point exists for which to mount a drive to, if not then it creates it.
##  EDIT: Change PATH to where you want to mount the drive.
$path = "\\wsl.localhost\Ubuntu\mnt\wsl\PHYSICALDRIVE1"
If(!(test-path $path))
{
      New-Item -ItemType Directory -Force -Path $path
}

#  This mounts your drive as bare without mounting any partitions. Necessary before invoking Veracrypt to mount the partition itself.
wsl --mount \\.\PHYSICALDRIVE1 --bare

#  This runs Veracrypt correctly for cross-compatibility between Powershell and WSL.
##  EDIT: Remove '-tc' if your encrypted drive is not encrypted in Truecrypt. Change your mount location from /dev/sdc1 if sdc1 is already used by something else.
wsl veracrypt -tc -m=nokernelcrypto /dev/sdc1
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • Except for quoting and escaping rules, calling CLIs from PowerShell is no different than from `cmd.exe`. Given that your argument (`/mnt/wsl/PHYSICALDRIVE1`) doesn't need quoting, your question is really about `veracrypt`'s command-line syntax. – mklement0 Jun 24 '21 at 18:41
  • Doesn't `veracrypt` accept the mount path as a separate argument? eg. `wsl veracrypt -tc -m=nokernelcrypto /dev/sdc1 /mnt/wsl/PHYSICALDRIVE1` – Mathias R. Jessen Jun 24 '21 at 18:41
  • Thank you @MathiasR.Jessen! – Ahenobarbus Jul 16 '21 at 06:32

0 Answers0