PowerShell安装模块时,可能会提示无法访问PSGallery,此时Get-PSRepository执行后获得InstallationPolicy是untrusted.
如果直接执行
Set-PSRepository -Name PSGallery -InstallationPolicy trusted
是无法生效的,因为.net4中没有启用额外的加密协议,会导致访问PSGallery失败.
此时需要向.net4的注册表添加安全协议生效的项目
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
然后再次执行
Set-PSRepository -Name PSGallery -InstallationPolicy trusted