PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Install-Module is not working properly with -Proxy

Open brunosaboia opened this issue 3 years ago • 8 comments

Steps to reproduce

Run Install-Module behind a proxy:

Install-Module posh-git -Scope CurrentUser -Proxy http://127.0.0.1:3128

Expected behavior

Installed-Module should use the specified proxy, such as in Invoke-WebRequest:

Invoke-WebRequest -Proxy http://127.0.0.1:3128 https://www.powershellgallery.com/api/v2

StatusCode        : 200
StatusDescription : OK
Content           : <?xml version="1.0" encoding="utf-8"?><service xml:base="https://www.powershellgallery.com/api/v2" xmlns="http://www.w3.org/2007/app" x
                    mlns:atom="http://www.w3.org/2005/Atom"><workspace><atom:title ty…
RawContent        : HTTP/1.1 200 OK

(output truncated for brevity)

Actual behavior

Proxy setting is ignored or incorrectly used (the DNS failure is an indication of that, as I have the same issue if I try ping www.powershellgallery.com):

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.                                                                       Install-Package: C:\program files\powershell\7-preview\Modules\PowerShellGet\PSModule.psm1:9711                                                             Line |
9711 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and module name 'posh-git'. Try Get-PSRepository to see all available registered
     | module repositories.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0-rc.2
PSEdition                      Core
GitCommitId                    7.1.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

brunosaboia avatar Nov 04 '20 11:11 brunosaboia

@brunosaboia Please open issue in PowerShellGet repository.

iSazonov avatar Nov 06 '20 10:11 iSazonov

Hi, is there any workaround for this problem? I am facing the same issue in our corporate environment for our servers.

 Invoke-WebRequest https://powershellgallery.com -Proxy http://proxy:8080 -ProxyUseDefaultCredentials

StatusCode        : 200
StatusDescription : OK
Install-Module -Name DockerMsftProvider -Proxy http://proxy:8080
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9711
Line |
9711 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and module name 'DockerMsftProvider'. Try Get-PSRepository to see all available registered module repositories.

astaruch avatar Jun 09 '21 16:06 astaruch

Hi @astaruch, thanks for sharing this. Are you facing any issues when you run this command without the -Proxy parameter? If you are not facing issues, can you run this command again: Install-Module -Name DockerMsftProvider -Proxy http://proxy:8080 -Verbose -Debug (but now with Verbose and Debug switches). This will help us get more information on this issue.

anamnavi avatar Jun 10 '21 18:06 anamnavi

Hi, i'm facing similar proxy issues. I configured my workplace proxy on powershell via netsh, logged in with my network user (i have admin rights) but can't ping anything or install any module. The -Proxy parameter doesn't work as well. Anyone have an idea of what could be wrong? image

quatis avatar Oct 21 '21 11:10 quatis

the ping results are 100% timeout btw

quatis avatar Oct 21 '21 11:10 quatis

@quatis can you try registering the PSGallery Repository with Register-PSRepository -Default? Let us know if this resolves your problem but if it does not can you try Invoke-WebRequest https://www.powershellgallery.com/api/v2 -Proxy <Your Proxy> -ProxyCredentials <If necessary, your creds>.

StevenBucher98 avatar Oct 21 '21 18:10 StevenBucher98

Hi, same issue here. Corporate proxies are going to be pretty common with their customer base, seems like an odd oversight by Microsoft.

PS C:\Windows\system32> Install-Module -Name PSWindowsUpdate -Proxy http://user:[email protected] -Verbose -Debug

DEBUG: 00:00:00 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0'.

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 00:00:00.0002313 Attempting to load PowerShell Provider Module [C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1]
DEBUG: 00:00:00.0006750 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ServerManagerTasks'.
DEBUG: 00:00:00.0567263 Loaded PowerShell package provider: '[C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1]'.

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\user\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider
now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
VERBOSE: Installing NuGet provider.
DEBUG: 00:00:00 Calling SearchForPackages. Name='NuGet'

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
VERBOSE: Using the provider 'Bootstrap' for searching packages.
DEBUG: 00:00:00.0048440 PackageProvider::FindPackage with name NuGet
DEBUG: 00:00:00.0052941 Calling SearchForPackages After Select 1
VERBOSE: Finding the package 'Bootstrap::FindPackage' 'NuGet','','2.8.5.201','''.
DEBUG: 00:00:00.0235868 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\hytl5n2j.fmf','40000','False'
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '2' more times.
DEBUG: 00:00:00.0919538 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\hytl5n2j.fmf','40000','False'
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '1' more times.
DEBUG: 00:00:00.1643516 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\hytl5n2j.fmf','40000','False'
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '0' more times.
WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\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 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 char:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

DEBUG: 00:00:00 Calling ImportPackageProvider. providerName = 'NuGet', requiredVersion='', minimumVersion = '2.8.5.201', maximumVersion=''

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 00:00:00.0000773 Calling ImportPackageProviderViaName. providerName = 'NuGet', requiredVersion='', minimumVersion = '2.8.5.201', maximumVersion=''
DEBUG: 00:00:02.5928672 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0'.
PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 char:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider

DEBUG: 00:00:00.0000003 Calling ImportPackageProvider. providerName = 'NuGet', requiredVersion='', minimumVersion = '', maximumVersion=''

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 00:00:00.0000319 Calling ImportPackageProviderViaName. providerName = 'NuGet', requiredVersion='', minimumVersion = '', maximumVersion=''
DEBUG: 00:00:02.4276344 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0'.
DEBUG: 00:00:02.4281121 Attempting to load PowerShell Provider Module [C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1]
DEBUG: 00:00:02.4283580 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ServerManagerTasks'.
DEBUG: 00:00:02.4771861 Loaded PowerShell package provider: '[C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1]'.
VERBOSE: No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
DEBUG: 00:00:02.4782736 PackageProvider::FindPackage with name NuGet
VERBOSE: Finding the package 'Bootstrap::FindPackage' 'NuGet','','0.0.0.1','''.
DEBUG: 00:00:02.4968569 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\1lcf0plg.u5u','40000','False'
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '2' more times.
DEBUG: 00:00:02.6024370 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\1lcf0plg.u5u','40000','False'
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '1' more times.
DEBUG: 00:00:02.6438242 Calling 'WebDownloader::DownloadFile' 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409','C:\Users\user\AppData\Local\Temp\Microsoft.PackageManagement\1lcf0plg.u5u','40000','False'
VERBOSE: Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '0' more times.
WARNING: Unable to download the list of available providers. Check your internet connection.
PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7415 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1
+ Install-Module -Name PSWindowsUpdate -Proxy http://user:Ca ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module

Register-PSRepository -Default has the same issues, with or without specifying -Proxy, where it answers: WARNING: Unable to download the list of available providers. Check your internet connection.

floptical avatar Oct 26 '21 14:10 floptical

Thanks @floptical! We noticed you are also running PowerShellGet v1.0.0, can you try updating following these steps here. This might solve your problem.

Can you try run Invoke-WebRequest https://www.powershellgallery.com/api/v2 -Proxy <Your Proxy> -ProxyCredentials <If necessary, your creds> and see if this works.

StevenBucher98 avatar Oct 28 '21 18:10 StevenBucher98