vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Vagrant not able to run powershell command.

Open jykgit201 opened this issue 3 years ago • 13 comments

Vagrant version 2.0.3

Host operating system Win 10 Pro

Guest operating system Ubuntu

Output of vagrant up Vagrant failed to initalize at a very early stage.

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

Installed version: N/A Minimum required version: 3

Linked to issue #9629

jykgit201 avatar May 09 '21 04:05 jykgit201

While in a search it identified that a power shell switch ‘-Noninteractive’ is not being working In my organisation system, mostly It’s due to some patch. Since the switch fails vagrant unable to identify the power shell version hence error. Will it be a good idea to remove this flag and proceed?

jykgit201 avatar May 10 '21 01:05 jykgit201

I've started to have similar problem after upgrading couple of weeks/months ago (not really sure when) in git-bash running in ConEmu (not when bash is run from Start menu neither in cmd). The funny part is it actually shows the version of powershell:

$ vagrant
5
Vagrant failed to initialize at a very early stage:

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

  Installed version: N/A
  Minimum required version: 3

This is the output from:

$ which powershell
/c/WINDOWS/System32/WindowsPowerShell/v1.0/powershell

$ powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\some-path-here> Write-Output $PSVersionTable.PSVersion.Major
5

I'm not sure what's with ConEmu that causes this, running vagrant --debug shows this snippet around the problem:

 INFO subprocess: Starting process: ["C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0/powershell.EXE", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", "Write-Output $PSVersionTable.PSVersion.Major"]
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
5
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 30
DEBUG subprocess: Exit status: 0
ERROR vagrant: Vagrant experienced an error! Details:
ERROR vagrant: #<Vagrant::Errors::PowerShellInvalidVersion: The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

Luckily, it works with plain cmd still, so it's not a blocker for me, but it is annoying as I had to stop using the same terminal for everything.

virgo47 avatar May 10 '21 08:05 virgo47

I am also experiencing this issue. Good to know about the cmd workaround @virgo47

verisk-dhaskin avatar May 20 '21 21:05 verisk-dhaskin

This doesn't work in cmd for me, just confirmed. :( EDIT: IT TOTALLY works, just not from cmd inside conemu. CURIOUS. Maybe conemu has something to do with it @virgo47

verisk-dhaskin avatar May 20 '21 21:05 verisk-dhaskin

Yeah, that's why I mentioned ConEmu and what I meant by plain cmd, sorry I wasn't clearer. We're using ConEmu (or some alternative) because Windows has no good console (or whatever it technically is) but it's not the first time it caused some issue with other software - either directly or because of some interplay, I really don't know. It actually runs from git-bash too, just run it from Start menu without ConEmu (at least with my setup it runs without ConEmu). So I don't know what is the problem, this goes beyond my knowledge of ConEmu and/or PowerShell and/or Vagrant, powershell works in ConEmu, but not for Vagrant.

virgo47 avatar May 20 '21 22:05 virgo47

This seems to be closed on Vagrant side: https://github.com/hashicorp/vagrant/issues/12221 And this is the relevant issue on ConEmu side: https://github.com/Maximus5/ConEmu/issues/2290 I'm not sure this is the original poster's problem but it seems so.

virgo47 avatar May 20 '21 22:05 virgo47

BTW: Disabling "Inject ConEmuHk.dll into all processes started in ConEmu tabs" under Settings > General may help, see: https://github.com/Maximus5/ConEmu/issues/2296#issuecomment-826542226 I tried it and vagrant works with ConEmu now. Although, looking at the tooltip for the option god knows what will not work now. :-)

virgo47 avatar May 20 '21 22:05 virgo47

I am seeing this also with 2.2.16 and 2.2.17 with ConEmu 210304 and pwsh 7.

@virgo47 workaround works for me.

Machine boots and runs, network works but vagrant can't see it, I assume this is a different problem, will try to duplicate on pwsh7 launched directly from start menu to isolate.

EDIT: Same issue with pwsh7 directly launched from start-menu, so it seems to be a different issue. I will have to search for that issue.

λ  vagrant up
Loading Vagrantfile.local
Bringing machine 'default' up with 'hyperv' provider...
==> default: Verifying Hyper-V is enabled...
==> default: Verifying Hyper-V is accessible...
    default: Configuring the VM...
    default: Setting VM Enhanced session transport type to HvSocket
==> default: Starting the machine...
==> default: Waiting for the machine to report its IP address...
    default: Timeout: 180 seconds
Hyper-V failed to determine your machine's IP address within the
configured timeout. Please verify the machine properly booted and
the network works. To do this, open the Hyper-V manager, find your
virtual machine, and connect to it.

The most common cause for this error is that the running virtual
machine doesn't have the latest Hyper-V integration drivers. Please
research for your operating system how to install these in order
for the VM to properly communicate its IP address to Hyper-V.

TonyApuzzo avatar Jul 08 '21 18:07 TonyApuzzo

run in git bash (for which command)

01418019@SF0001418019A MINGW64 ~
$ which powershell
/c/Windows/System32/WindowsPowerShell/v1.0/powershell

01418019@SF0001418019A MINGW64 ~
$ which pwsh
/c/Program Files/PowerShell/7/pwsh

01418019@SF0001418019A MINGW64 ~
$ powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major

01418019@SF0001418019A MINGW64 ~
$ pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
.PSVersion.Major

run in powershell

PS C:\Users\01418019> $PSVersionTable.PSVersion.Major
5
PS C:\Users\01418019> powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
PS C:\Users\01418019> pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
5
// remove -NoLogo
PS C:\Users\01418019> powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
5

run in pwsh

PS C:\Users\01418019> $PSVersionTable.PSVersion.Major
7
PS C:\Users\01418019> powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
PS C:\Users\01418019> pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
7
// remove -NoLogo
PS C:\Users\01418019> powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output $PSVersionTable.PSVersion.Major
7

So it seems it's powershell 's bug.

So I run cp /c/Program Files/PowerShell/7/pwsh.exe /c/Program Files/PowerShell/7/powershell.exe and move C:\Program Files\PowerShell\7\ to before %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ in SystemEnviromentVarible. Done. 😓

PS C:\Users\01418019> vagrant version
Installed Version: 2.2.18
Latest Version: 2.2.18

You're running an up-to-date version of Vagrant!

xialvjun avatar Oct 28 '21 02:10 xialvjun

@xialvjun Funny, I have only PS 5 in the first path just like you, I have no pwsh at all at the path you do. I tried this in shell today:

$ powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output '$PSVersionTable.PSVersion.Major'
5

Quoting at the end fixes the output, but it does produce some even with -NoLogo. I tried vagrant and it works again. So, whatever the issue was, it repaired itself somehow on my computer.

virgo47 avatar Oct 28 '21 07:10 virgo47

@virgo47 I installed PS7(pwsh) which didn't overwrite the default PS5(powershell) in windows10.

xialvjun avatar Oct 28 '21 14:10 xialvjun

Yeah, this seems to have resolved itself somehow.

I am able to run vagrant now under cmder both with PowerShell 5.1 and pwsh 7.1.5 where it was failing with both before.

TonyApuzzo avatar Oct 28 '21 22:10 TonyApuzzo

@xialvjun Funny, I have only PS 5 in the first path just like you, I have no pwsh at all at the path you do. I tried this in shell today:

$ powershell -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command Write-Output '$PSVersionTable.PSVersion.Major'
5

Quoting at the end fixes the output, but it does produce some even with -NoLogo. I tried vagrant and it works again. So, whatever the issue was, it repaired itself somehow on my computer.

Ran this and it worked. Thanks @virgo47

philipsdotdev avatar Jun 25 '22 14:06 philipsdotdev