如何在安装VS代码后修复powershell



我已经在这里问了一个类似的问题:https://superuser.com/questions/1613630/most-of-powershell-commands-not-working?noredirect=1基本上,我没能解决这个问题,所以我换了一台电脑。全新的开始设置它,只做了以下操作:

  • 已安装VS代码
  • 在VS代码中打开Powershell扩展
  • 它提示包管理器需要更新,否则将无法正常工作
  • 要求我安装NuGet以获得软件包管理器
  • 之后PowerShell 5.1再次停止工作

模块没有自动加载,powershell的新实例会这样做:

PS C:WINDOWSsystem32> Write-Host
Write-Host : The term 'Write-Host' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify 
that the path is correct and try again.
At line:1 char:1
+ Write-Host
+ ~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

有什么想法吗?

这为我修复了它:

(Get-Module -ListAvailable).Name | %{Import-Module -Name $_ -Force}
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
Install-Module -Name PackageManagement -Force -RequiredVersion 1.4.6 -Scope AllUsers -AllowClobber -Verbose

然后,如果最后一个命令没有安装NuGet,请执行以下操作:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

最新更新