不知道为什么,powershell 用的 SecurityProtocol 仍然是早就被弃用的 TLS 1.0,所以要改成 TLS1.2 就可以安装 NuGet 了。
1,用这个查看 SecurityProtocol 使用的是什么:
[Net.ServicePointManager]::SecurityProtocol
2,然后修改为 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3,安装 Nuget:
Install-PackageProvider -name "nuget"
4,安装自己需要的 module:
Install-Module SharePointPnPPowerShellOnline
参考:
https://www.alitajran.com/unable-to-install-nuget-provider-for-powershell/
https://devblogs.microsoft.com/powershell/powershell-gallery-tls-support/