我读了很多论坛并尝试了很多东西,但我就是无法添加PS图库
我使用公司代理,但我已设置我的个人资料以使用它。我正在尝试使用这些命令注册 PS 存储库
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://myproxy:1234')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
Register-PSRepository -default -Proxy http://myproxy:123
Get-PSRepository
Get-PSRepository
总是返回警告WARNING: Unable to find module repositories
我使用的是 Windows Server 2012 R2。
我已经通过下载外部 URL 验证了代理可以访问互联网,因此绝对不是代理不正确的问题
如何注册 PSGallery?这快把我逼疯了!
谢谢
PS:Powershell版本
Name Value
---- -----
PSVersion 5.1.14409.1018
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14409.1018
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
UPDATE
我发现我们的公司代理正在阻止对 powershellgallery 的请求,这可以解释我面临的大部分问题。该代理允许其他 http 流量,但以某种方式阻止 powershellgallery。我将与网络团队联系,并在了解更多信息后更新此线程。
我从这篇文章中得到了一些“灵感”Register-PSRepository 上出现无效 Web Uri 错误 https://stackoverflow.com/questions/35296482/invalid-web-uri-error-on-register-psrepository/35296483#35296483
想出了一种暴力方法,可能会帮助将来的人
- 在 C:\Users\AppData\Local\Microsoft\Windows\PowerShell 中创建一个名为“PowershellGet”的文件夹。如果存在则进入下一步
- 在该文件夹中,创建一个文件 PSRepositories.xml。如果已经存在,请进行备份。该文件的内容是:
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<TN RefId="0">
<T>System.Collections.Specialized.OrderedDictionary</T>
<T>System.Object</T>
</TN>
<DCT>
<En>
<S N="Key">PSGallery</S>
<Obj N="Value" RefId="1">
<TN RefId="1">
<T>Microsoft.PowerShell.Commands.PSRepository</T>
<T>System.Management.Automation.PSCustomObject</T>
<T>System.Object</T>
</TN>
<MS>
<S N="Name">PSGallery</S>
<S N="SourceLocation">https://www.powershellgallery.com/api/v2/</S>
<S N="PublishLocation">https://www.powershellgallery.com/api/v2/package/</S>
<S N="ScriptSourceLocation">https://www.powershellgallery.com/api/v2/items/psscript/</S>
<S N="ScriptPublishLocation">https://www.powershellgallery.com/api/v2/package</S>
<B N="Trusted">true</B>
<B N="Registered">true</B>
<S N="InstallationPolicy">Trusted</S>
<S N="PackageManagementProvider">NuGet</S>
<Obj N="ProviderOptions" RefId="2">
<TN RefId="2">
<T>System.Collections.Hashtable</T>
<T>System.Object</T>
</TN>
<DCT />
</Obj>
</MS>
</Obj>
</En>
</DCT>
</Obj>
</Objs>
我直接添加了 SourceLocation、PublishLocation 等位置
完成后,现在启动一个新的 PS 窗口并输入 Get-PSRepository,它应该显示此存储库。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)