我按照Using PowerShell Behind a Proxy中提到的步骤配置了代理服务器。
netsh winhttp set proxy "[IP]:[Port]"
$Wcl = New-Object System.Net.WebClient
$Creds = Get-Credential
$Wcl.Proxy.Credentials = $Creds
弹出一个对话框,在第三行收集我的凭据。
然后我尝试安装NuGet:
PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/
?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet
connection.
Install-PackageProvider : No match was found for the specified search criteria
for the provider 'NuGet'. The package provider requires 'PackageManagement' and
'Provider' tags. Please check if the specified package has the tags.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider
错误消息似乎表明我的PowerShell无法连接到Internet,但是当我尝试此命令时:
PS C:\Users\Administrator> Invoke-WebRequest "https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409"
StatusCode : 200
StatusDescription : OK
Content : <?xml version="1.0" encoding="utf-8"?>
<SoftwareIdentity xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:discovery="http://p...
RawContent : HTTP/1.1 200 OK
Content-MD5: 01uMBNqAHedJsS1dqKC5oA==
Vary: Accept-Encoding
X-Cache: HIT
x-ms-blob-type: BlockBlob
x-ms-lease-status: unlocked
x-ms-request-id: 1b7af5a7-901e-0003-5d94-f5cc950000...
Forms : {}
Headers : {[Content-MD5, 01uMBNqAHedJsS1dqKC5oA==], [Vary, Accept-Encoding], [X-Cache, HIT],
[x-ms-blob-type, BlockBlob]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : System.__ComObject
RawContentLength : 1847
似乎毕竟可以连接到互联网。
我做错了什么?如何安装NuGet?
编辑: 我尝试了Ocaso Protal的建议:
PS C:\Users\Administrator> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -proxy [ProxyServer:Port] -proxycredential $Creds
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package
provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
kageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
vider
PS C:\Users\Administrator> $Creds
UserName Password
-------- --------
[My UserName] System.Security.SecureString
似乎没有效果。
答案 0 :(得分:13)
根据https://community.spiceworks.com/topic/2265662-powershell-get-download-problem
我今天遇到了同样的问题...
我的问题是PowerShell画廊无法在W2016盒子上下载任何内容:
VERBOSE: InstallPackage' - name='AzureRM.BootStrapper',
version='0.5.0',destination='C:\Users\Administrator\AppData\Local\Temp\2\1254134668'
VERBOSE: DownloadPackage' - name='AzureRM.BootStrapper',
version='0.5.0',destination='C:\Users\Administrator\AppData\Local\Temp\2\1254134668\AzureRM.BootStrapper\AzureRM.BootSt
rapper.nupkg', uri='https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0'.
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0' for '2' more
times
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0' for '1' more
times
VERBOSE: An error occurred while sending the request.
VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0' for '0' more
times
VERBOSE: Downloading package 'AzureRM.BootStrapper' failed, please make sure
'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0' is accessable.
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/AzureRM.BootStrapper/0.5.0' is not valid.
PackageManagement\Install-Package : Package 'AzureRM.BootStrapper' failed to download.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\Admini...tStrapper.nupkg:String) [Install-Package], Excep
tion
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPac
kage
帮助我找出它是TLS v1.2的原因是Fiddler中的此错误:
System.Security.Authentication.AuthenticationException A call to SSPI failed, see inner exception
从那里我得到了-> A call to SSPI failed, see inner exception - The Local Security Authority cannot be contacted
然后在本地进行测试:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
哪个工作正常!
希望这会在将来对某人有所帮助:-)
您可以通过编辑注册表为整个.NET框架进行设置:
# Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
# Set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
这是几天前在Windows Server 2016 Datacentre机器上发生的,Win 2019仍然可以正常工作。
命令归功于: https://johnlouros.com/blog/enabling-strong-cryptography-for-all-dot-net-applications
快乐的Azure堆叠!!!
答案 1 :(得分:6)
可能与TLS安全性相关(参考:https://rnelson0.com/2018/05/17/powershell-in-a-post-tls1-1-world/)
请先尝试以下命令: [Net.ServicePointManager] :: SecurityProtocol = [Net.SecurityProtocolType] :: Tls12
然后尝试进行更新。 注意:该命令仅影响当前会话,不会持久。
您还可以检查计算机上设置的客户端TLS版本。看起来客户端需要TLS 1.0。 (参考:https://powershell.org/forums/topic/wmf-5-1-upgrade-broken-repositories/)
迈克尔
答案 2 :(得分:5)
尝试一下:
[System.Net.WebRequest]::DefaultWebProxy.Credentials = System.Net.CredentialCache]::DefaultCredentials
如果上述方法无效,请尝试以下操作:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12