I followed the steps mentioned in Using PowerShell Behind a Proxy to configure my proxy server.
netsh winhttp set proxy "[IP]:[Port]"
$Wcl = New-Object System.Net.WebClient
$Creds = Get-Credential
$Wcl.Proxy.Credentials = $Creds
Run Code Online (Sandbox Code Playgroud)
A dialog popped up to collect my credential on the third line.
Then I tried to install 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
Run Code Online (Sandbox Code Playgroud)
The error message seems to indicate my PowerShell cannot connect to internet, but when I tried this command:
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
Run Code Online (Sandbox Code Playgroud)
It seems it can connect to the Internet after all.
What did I do wrong? How do I install NuGet?
EDIT: I tried Ocaso Protal's suggestion:
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
Run Code Online (Sandbox Code Playgroud)
It seems to have no effect.
小智 19
根据https://community.spiceworks.com/topic/2265662-powershell-get-download-problem
我今天遇到了同样的问题...
我的问题是 PowerShell Gallery 不会在 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
Run Code Online (Sandbox Code Playgroud)
帮助我发现它是 TLS v1.2 的是 Fiddler 中的这个错误:
System.Security.Authentication.AuthenticationException A call to SSPI failed, see inner exception
Run Code Online (Sandbox Code Playgroud)
从那里我得到了这个 ->对 SSPI 的调用失败,请参阅内部异常 - 无法联系本地安全机构
然后在本地测试:
System.Security.Authentication.AuthenticationException A call to SSPI failed, see inner exception
Run Code Online (Sandbox Code Playgroud)
哪个工作得很好!
希望这会在未来对某人有所帮助:-)
您可以通过编辑注册表为整个 .NET 框架设置它:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)
这发生在几天前的 Windows Server 2016 Datacenter 机器上,Win 2019 仍然可以正常工作。
命令感谢:https : //johnlouros.com/blog/enabling-strong-cryptography-for-all-dot-net-applications
快乐的 Azure 堆叠!!!
尝试这个:
[System.Net.WebRequest]::DefaultWebProxy.Credentials = System.Net.CredentialCache]::DefaultCredentials
Run Code Online (Sandbox Code Playgroud)
如果上述方法不起作用,请尝试以下操作:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)
可能与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/)
麦可
| 归档时间: |
|
| 查看次数: |
1083 次 |
| 最近记录: |