ShahradR / windows-dev

Windows development image used for personal projects
MIT License
0 stars 0 forks source link

Vagrant cannot find PowerShell when running #4

Open ShahradR opened 4 years ago

ShahradR commented 4 years ago

When running Vagrant in WSL, the following error message is returned:

The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade to the installed version of
powershell to the minimum required version and run the command again.

  Installed version:

  Minimum required version: 3
ShahradR commented 4 years ago

Tried installing Vagrant on both WSL and Linux with the same version, but the problem still occurs.

ShahradR commented 4 years ago

Ran Process Explorer, and found that the following command is ran by Vagrant to determine the PowerShell version:

powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command "Write-Output $PSVersionTable.PSVersion.Major"

The process to find the above command is illustrated in the GIF below: vagrant-ps-procexp

ShahradR commented 4 years ago

Running the PowerShell command in WSL manually, we see that it returns the expected major version number, 5.

image (Note that we have to escape the $ symbol or Bash will try to resolve PSVersionTable as a variable.)

ShahradR commented 4 years ago

Running Vagrant with the -debug flag shows some additional insights. It seems that there are two lines returned from the PowerShell command's output: the expected major version number of 5, but also a blank line. It is possible that Vagrant is only picking up the last empty line, and comparing it to the minimum supported PS version of 3.

image

ShahradR commented 4 years ago

Changing the WSL version from 2 back to 1 resolves the issue – the vagrant init command now completes successfully.

image

ShahradR commented 4 years ago

Notice that, in the debug output for the vagrant init command, the blank line seen from the PowerShell command output in WSL 2 is absent once the distribution is converted back to WSL 1.

image