通过命令行更新 Powershell

Los*_*nos 25 powershell command-line powershell-5.0

我想更新机器的Powershell版本。这可以通过命令行完成吗?

我目前的需求是在 Windows 服务器 2012R2 上从 PS 4 更新到 PS 5。

我想对于所有 Windows 版本和所有 PS 版本都没有一个包罗万象的解决方案,并且混合了像PS4 需要 Dotnet4.5这样的警告,所以让我们让问题尽可能简单,就像上面的前两句话一样。

小智 25

运行此命令: iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

然后使用您的参数运行 MSI。

在此之后,您需要更新模块。

参考:

https://www.thomasmaurer.ch/2019/03/how-to-install-and-update-powershell-6/

https://www.thomasmaurer.ch/2019/02/update-powershellget-and-packagemanagement/

  • [此处](https://www.hanselman.com/blog/InstallingPowerShellWithOneLineAsANETCoreGlobalTool.aspx) 也可能是一种作为 dotnet 全局工具的方法。`dotnet tool install --global PowerShell` 不过我还没有尝试过。 (2认同)

小智 16

以管理员身份打开 Powershell 并键入以下命令:

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
Run Code Online (Sandbox Code Playgroud)

如果要更新到最新预览,请-Preview在末尾添加参数:

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -Preview"
Run Code Online (Sandbox Code Playgroud)