在旧版本的windows上执行powershell命令时,时不时出现一些奇怪的问题,常要花不少时间去摸索解决,现记录如下。


Windows Server 2012 R2

安装PowerShell 5

https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win8.1AndW2K12R2-KB3191564-x64.msu

完成后检查版本:Get-Host

PowerShell的安装与升级_Server


Windows Server 2012 Standard

默认PowerShell版本时 3,检查命令:$PSVersionTable

PowerShell的安装与升级_PowerShell_02

升级的话,需要先安装Widows Management Framework (WMF), 下载:

https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf-overview?view=powershell-7.4

PowerShell的安装与升级_升级_03

PowerShell的安装与升级_升级_04

下载后安装会提示重启

PowerShell的安装与升级_PowerShell_05

然后下载PowerShell 7安装

https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4

PowerShell的安装与升级_PowerShell_06

完成后实际上PowerShell升级成 5

PowerShell的安装与升级_升级_07