我看了很多论坛,也试过很多东西,就是无法添加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 验证了代理可以访问互联网,所以代理不正确绝对不是问题
如何注册 PS Gallery?这让我发疯!
谢谢 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
更新
我发现我们的公司代理阻止了对 powershellgallery 的请求,这可以很好地解释我面临的大部分问题。该代理允许其他 http 流量,但以某种方式阻止了 powershellgallery。一旦我发现更多信息,我会与网络团队联系并更新此线程。
最佳答案
我从这篇文章中得到了一些“灵感” Invalid Web Uri error on Register-PSRepository
想出了一个可能对将来的人有帮助的蛮力方法
<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,它应该会显示这个 repo。
https://stackoverflow.com/questions/65598837/