现象:

Windows 10环境,vagrant 安装完成之后执行vagrant version有如下报错

C:\Users\Administrator>vagrant version
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

C:\Users\Administrator>

这里提示powershell 的版本“Installed version: N/A”,也就是找不到powershell

其实powershell是已经安装了的,见下:


Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。

尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS C:\Users\Administrator> $PSVersionTable;

Name Value
---- -----
PSVersion 5.1.19041.1023
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1023
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1


PS C:\Users\Administrator>

解决方法:开始-运行-sysdm.cpl-系统属性-高级-环境变量-系统变量-找到名为PATH的系统变量-点击编辑-新加如下内容C:\Windows\System32\WindowsPowerShell\v1.0

然后退出cmd,再重新打开一个cmd,重新运行vagrant version即可

C:\Users\Administrator>vagrant version
Installed Version: 2.2.16
Latest Version: 2.2.16

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

C:\Users\Administrator>