PowerShellGallery icon indicating copy to clipboard operation
PowerShellGallery copied to clipboard

Unable to resolve package source 'https://www.powershellgallery.com/api/v2'

Open pbuffolino opened this issue 4 years ago • 30 comments

SImilar to issues posted earlier; I am unable to download and install packages from multiple machines.

  • Checked and Verified TLS 1.2
  • Unregistered / Registered PSRepository
  • Attempted Force Update of PackageProvider
  • Attempted Force Update of PowerShellGet Module
  • Tested from Multiple Machines (Windows 10, Server 2012 R2, Server 2016)

Fiddler shows this: [Fiddler] The connection to 'psg-prod-eastus.azureedge.net' failed. Error: TimedOut (0x274c). System.Net.Sockets.SocketException A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

pbuffolino avatar Feb 03 '21 08:02 pbuffolino

Hi, when did this occur? On Monday 2/1 we did have a brief period (roughly between 8:30 and 10am PST) where our CDN availability dropped. It's been consistently at 100% since then. If your issue happened outside of this time frame (especially if it's still occurring), we can dig a little deeper to try to figure out what's going on.

alerickson avatar Feb 04 '21 00:02 alerickson

Same issue here : WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2/'.

Windows 8.1 x64

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

Saved-by-Him avatar Feb 09 '21 03:02 Saved-by-Him

Thanks everyone, would be great to know if you have had trouble installing packages in the past on this system or if this is a new issue, also could you please provide the output of Get-Module PackageManagement, PowerShellGet -ListAvailable, Get-PackageSource PSGallery and also the command you were trying to run when you hit this issue with the -Verbose and -Debug switches.

SydneyhSmith avatar Feb 10 '21 19:02 SydneyhSmith

Updating this thread -

It turns out that psg-prod-eastus.azureedge.net was blocked by IP on a Firewall. I will have more feedback tomorrow if this is resolved.

Thank you!

pbuffolino avatar Feb 10 '21 19:02 pbuffolino

[REDACTED] ~\Documents\WindowsPowerShell> Get-Module PackageManagement, PowerShellGet -ListAvailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands


Script 1.4.7 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.4 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.3.2 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.2.4 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.2.3 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.1.7.2 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.1.7.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 1.1.4.0 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...} Script 2.1.4 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...} Script 2.0.3 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...} Script 1.6.6 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...} Script 1.6.5 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...} Script 1.1.3.2 PowerShellGet {Install-Module, Find-Module, Save-Module, Update-Module...}


[REDACTED] ~\Documents\WindowsPowerShell> Get-PackageSource PSGallery

Name ProviderName IsTrusted Location


PSGallery PowerShellGet False https://www.powershellgallery.com/api/v2/


[REDACTED] ~\Documents\WindowsPowerShell> Find-Module -Name Powershell* -Repository PSGallery -Verbose VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MetaProvider.PowerShell.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsiProvider.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.ArchiverProviders.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.CoreProviders.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.NuGetProvider.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsuProvider.dll VERBOSE: Acquiring providers for assembly: C:\Program Files\PackageManagement\ProviderAssemblies\chocolatey\2.8.5.130\ChocolateyPrototype.exe VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2/'; IsTrusted = 'False'; IsRegistered = 'True'. VERBOSE: Using the provider 'PowerShellGet' for searching packages. VERBOSE: Using the specified source names : 'PSGallery'. VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'. VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/' and PackageManagementProvider is 'NuGet'. VERBOSE: An error occurred while sending the request. VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/' for '2' more times VERBOSE: An error occurred while sending the request. VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/' for '1' more times VERBOSE: An error occurred while sending the request. VERBOSE: Retry downloading 'https://www.powershellgallery.com/api/v2/' for '0' more times WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2/'. VERBOSE: Total package yield:'0' for the specified package 'Powershell*'. VERBOSE: Total package yield:'0' for the specified package 'Powershell*'. VERBOSE: No module found matching 'Powershell*'.

Saved-by-Him avatar Feb 19 '21 00:02 Saved-by-Him

Updating this thread -

It turns out that psg-prod-eastus.azureedge.net was blocked by IP on a Firewall. I will have more feedback tomorrow if this is resolved.

Thank you!

Whose firewall? It isn't mine because psg-prod-eastus.azureedge.net is up...

Pinging cs9.wpc.v0cdn.net [72.21.81.200] with 32 bytes of data: Reply from 72.21.81.200: bytes=32 time=30ms TTL=55

Ping statistics for 72.21.81.200: Packets: Sent = 1, Received = 1, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 30ms, Maximum = 30ms, Average = 30ms

Saved-by-Him avatar Feb 19 '21 00:02 Saved-by-Him

@Saved-by-Him can you run Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/' and share the output?

alerickson avatar Feb 19 '21 00:02 alerickson

@Saved-by-Him can you run Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/' and share the output?

[REDACTED] ~\Documents\WindowsPowerShell> Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/' -Verbose VERBOSE: GET https://www.powershellgallery.com/api/v2/ with 0-byte payload Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. At line:1 char:1

  • Invoke-WebRequest 'https://www.powershellgallery.com/api/v2/' -Verbos ...
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    
    

[REDACTED] ~\Documents\WindowsPowerShell> ping.exe -4 -n 1 www.powershellgallery.com.

Pinging psg-prod-centralus.cloudapp.net [168.61.186.235] with 32 bytes of data: Request timed out.

Ping statistics for 168.61.186.235: Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

Saved-by-Him avatar Feb 20 '21 02:02 Saved-by-Him

I have found a temporary workaround:

add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy


Then ----> [PS]> Find-Module -Name powershell* -Repository PSGallery -Verbose

WORKS!

:)

Solved, at least temporarily... :-P

Saved-by-Him avatar Feb 20 '21 08:02 Saved-by-Him

Based on this Could not establish trust relationship for the SSL/TLS secure channel. it looks like this may be a TLS issue and you may need to upgrade to the latest PowerShellGet (2.2.5), which handles temporary compatibility with TLS 1.2 on legacy TLS systems

SydneyhSmith avatar Feb 25 '21 22:02 SydneyhSmith

I do concur. I figured this was a trust issue. This will likely be fixed very soon, I'm certain...

It's a good thing Microsoft, Windows PowerShell, and PSGallery are ALWAYS super trustworthy! :P

I like the the old CIA motto:

In God we trust, for everyone else, we verify... (and we add exception for PSGallery since we can't live without POSH!)

The first thing I did was update: PowerShellGet, PackageManagement, and PSReadline.

PowerShellGet is now v2.2.5 :-)

All seems to be marvelous!

The second thing I did was:

[PS]> "# here's how you can make your computer sound like it's working hard:"
[PS]> Start-Job -Name ThinkingHard -ScriptBlock { while ($true){ [Console]::Beep( (Get-Random -Min 300 -Max 7000), 200) } }

Then when the boss is near, I do:

[PS]> Stop-Job -Name ThinkingHard -PassThru | Remove-Job

EOF>>

Saved-by-Him avatar Feb 27 '21 06:02 Saved-by-Him

I am behind a proxy so this is what worked for me using Powershell ISE.

Set TLS to 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 [Net.ServicePointManager]::SecurityProtocol

Use default creds for the proxy (New-Object -TypeName System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

mderouen avatar Mar 29 '21 12:03 mderouen

This is still open and I am having this issue.

PS C:\src\t> Get-PackageSource PSGallery

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
PSGallery                        PowerShellGet    True       https://www.powershellgallery.com/api/v2

PS C:\src\t> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\src\t> (New-Object -TypeName System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
PS C:\src\t> Find-Module -Repository psgallery -Name pswindowsupdate
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
Find-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:8879
Line |
8879 |          PackageManagement\Find-Package @PSBoundParameters | Microsoft …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and module name 'pswindowsupdate'. Try Get-PSRepository to see all available registered module repositories.

Liturgist avatar Aug 19 '21 22:08 Liturgist

This is still an issue for us when running Install-Module from an azure devops pipeline. It crashes about 80% of the time like so:

nuget                          2.8.5.201        https://onege... NuGet provider for the OneGet meta-package manager    
WARNING: Could not get response from query 
'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='dbatools'&$skip=240&$top=40'.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'dbatools'. Try 
Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:8879 char:9
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio 
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

QuadmanSWE avatar Aug 26 '21 15:08 QuadmanSWE

Experienced same problem with Powershell 7.1.4 image

Solved it using "regular" Powershell 5.1 image

reuvenab avatar Sep 01 '21 17:09 reuvenab

Experienced same problem with Powershell 7.1.4

Solved it using "regular" Powershell 5.1

5.1 = current "Windows PowerShell" 6.0+ = "PowerShell Core"

Liturgist avatar Sep 01 '21 17:09 Liturgist

@reuvenab I see that the installation for PowerShell 7.1.4 was done from the Microsoft Store. If you can repro the issue consistently it would help root cause the issue if you could try the same scenario by installing 7.1.4 using a MSI.

The package can be found here: https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x64.msi The instructions can be found here: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7.1#installing-the-msi-package

adityapatwardhan avatar Sep 02 '21 19:09 adityapatwardhan

I'm experiencing the same issue:

PS> Get-Module -ListAvailable Az* | Install-Module

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
Install-Package: C:\Users\alexbat\OneDrive - Microsoft\Documents\PowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:9711
Line |
9711 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters
     |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and module name 'Az'. Try Get-PSRepository to see all available registered module

Popular workaround I found in Google did nothing:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Environment:

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

I installed PSCore from MSI.

abatishchev avatar Sep 27 '21 17:09 abatishchev

I just suffered from this same experience, but when I opened a new pwsh instance and ran the same command it worked fine. Previous terminal still reported the same error.

jwittner avatar Oct 15 '21 22:10 jwittner

I just suffered from this same experience, but when I opened a new pwsh instance and ran the same command it worked fine. Previous terminal still reported the same error.

Same here but with PS5 running in ISE. "Have you tried turning it off and on again?" Yes, works!

stinos avatar Dec 09 '21 08:12 stinos

Same issue

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS> Get-PackageSource

Name                             ProviderName     IsTrusted  Location
----                             ------------     ---------  --------
nuget.org                        NuGet            False      https://api.nuget.org/v3/index.json
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2

PS> Find-PackageProvider Nuget
Find-PackageProvider: No match was found for the specified search criteria and package name 'Nuget'. Try Get-PackageSource to see all available registered package sources.

brianary avatar Feb 19 '22 00:02 brianary

Just adding this comment as reference to confirm that I too experienced same message described above (N.B. always shown as a WARNING : ...) but in very different configuration (Windows 7 SP1 Ultimate x64 obviously with PowerShell 5.1) and here are some more details of my system status when I initially experienced issue:

Click here if interested to see my test details

PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls

PS C:\Windows\system32> Update-Module -whatif -name SpeculationControl
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name
'SpeculationControl'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:12989 char:20
+ ...           $sid = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\Windows\system32> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2

PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Windows\system32> 
PS C:\Windows\system32> Update-Module -whatif -name SpeculationControl
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name
'SpeculationControl'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:12989 char:20
+ ...           $sid = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\Windows\system32> Get-InstalledModule -name PowerShell*

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.3.6                PowerShellCookbook                  PSGallery            Sample scripts from the Windows PowerS...
2.2.3                PowerShellGet                       PSGallery            PowerShell module with commands for di...
1.0.0.0              PowerShellGetGUI                    PSGallery            A GUI tool for managing PowerShell Gal...

PS C:\Windows\system32> Find-Module -Name PowerShellGet -MinimumVersion 2.2.3
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'PowerShellGet'.
Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:8873 char:9
+         PackageManagement\Find-Package @PSBoundParameters | Microsoft ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
   n
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

PS C:\Windows\system32> $PSVersionTable

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

Anyway also thanks to suggestions from previous commenters experiences I too tried to open a 2nd PowerShell session (always as an admin) that also helped me to solve and same message above was experienced no more :

Click here if also interested in these final status details


PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls
PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol
Tls12
PS C:\Windows\system32> Find-Module -Name "PowerShellGet" -MinimumVersion 2.2.4.1

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
2.2.5                PowerShellGet                       PSGallery            PowerShell module with commands for di...

PS C:\Windows\system32> Install-Module PowerShellGet -RequiredVersion 2.2.5

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Windows\system32> Find-Module -Name "PackageManagement" -MinimumVersion 1.4.7

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.4.7                PackageManagement                   PSGallery            PackageManagement (a.k.a. OneGet) is a...

PS C:\Windows\system32> Install-Module PackageManagement -RequiredVersion 1.4.7

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Windows\system32> $PSVersionTable

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

PS C:\Windows\system32> Get-InstalledModule -name PowerShell*

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.3.6                PowerShellCookbook                  PSGallery            Sample scripts from the Windows PowerS...
2.2.5                PowerShellGet                       PSGallery            PowerShell module with commands for di...
1.0.0.0              PowerShellGetGUI                    PSGallery            A GUI tool for managing PowerShell Gal...

PS C:\Windows\system32> Get-InstalledModule -name PackageMan*

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.4.7                PackageManagement                   PSGallery            PackageManagement (a.k.a. OneGet) is a...

PS C:\Windows\system32> 

P.S. If also of any interest too my 1st PS session was started as admin little after my PC started and I logged into it, and quite a lot of things happened on my PC with that session already silently running minimized before today I used it to switch to TLS 1.2 to then unsuccessfully try to install latest available PowerShellGet and PackageManagement that I definitely needed and now I too have... ;-)

SwimmeRM avatar Mar 25 '22 09:03 SwimmeRM

Here's a way faster workaround when Install Module or Search API fails:

function Install_Custom {
   [CmdletBinding()]
   param
   (   
       [String] $moduleName
   )
   $installed.Add($moduleName)
   $modulesPath = $($env:PSModulePath.Split(';')[0])
   Invoke-WebRequest -Uri https://www.powershellgallery.com/api/v2/package/$moduleName -OutFile "./$($moduleName)_latest.zip"
   mkdir "$modulesPath/$moduleName"
   Expand-Archive -Path "$($moduleName)_latest.zip" -DestinationPath "$modulesPath/$moduleName"
   Remove-Item -Path "$($moduleName)_latest.zip" -Force
   [xml]$info = Get-Content -Path "$modulesPath/$moduleName/$moduleName.nuspec"
   $version = $info.package.metadata.version
   Move-Item -Path "$modulesPath/$moduleName" -Destination "$modulesPath/$version"
   If (!(test-path $modulesPath/$moduleName)) {
       mkdir "$modulesPath/$moduleName"
   }
   Move-Item -Path "$modulesPath/$version" -Destination "$modulesPath/$moduleName/$version"
   $dependencies = $info.package.metadata.dependencies.dependency
   foreach ($dep in $dependencies) {
       $id = $dep.id
       if (! $installed.Contains($id)) {
           Install_Custom -moduleName $id
       }
   }
}

Usage Example

   $installed = [System.Collections.ArrayList]@()
   Write-Host "Custom Installing Module"
   Measure-Command { Install_Custom -moduleName "MicrosoftPowerBIMgmt" | Out-Default }
   Write-Host "Installed $installed"

choukimasri avatar Apr 15 '22 14:04 choukimasri

I'm experiencing the same issue, when executing a Powershell script within an Ansible play.

The error occurs when using the Ansible communtiy module win_psscript or triggering a Powershell script from the Ansible play where the Powershell script using one of the following commands

  • Find-Script -Repository $PSRepo -name $PSScriptName
  • Install-Script -Repository $PSRepo -name $PSScriptName
  • Install-Package $PSScriptName -Source $PSScriptSource

What i've noticed during debugging, if i Enter-PSSession to the computer (which the Ansible play is configuring), i get the same error when using the commands above. But if i RDP into the same computer (same user context) and run the same command, it works without errors/warnings.

The Powershell repository is not PSGallery, but a self-hosted NuGet server.

The machine is a Windows Server 2022 with the following Powershell version:

PSVersion                      5.1.20348.558
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.558
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

I have tried:

  • Checked and Verified TLS 1.2
  • Unregistered / Register PSRepository
  • Force Update of PackageProvider
  • Force Update of PowerShellGet Module
  • Checked and Verified internett connection
  • Not behind proxy

alexanderfelipeoines avatar Oct 04 '22 08:10 alexanderfelipeoines

I'm experiencing the same issue, when executing a Powershell script within an Ansible play.

The error occurs when using the Ansible communtiy module win_psscript or triggering a Powershell script from the Ansible play where the Powershell script using one of the following commands

* `Find-Script -Repository $PSRepo -name  $PSScriptName`

* `Install-Script -Repository $PSRepo -name  $PSScriptName`

* `Install-Package $PSScriptName -Source $PSScriptSource`

What i've noticed during debugging, if i Enter-PSSession to the computer (which the Ansible play is configuring), i get the same error when using the commands above. But if i RDP into the same computer (same user context) and run the same command, it works without errors/warnings.

The Powershell repository is not PSGallery, but a self-hosted NuGet server.

The machine is a Windows Server 2022 with the following Powershell version:

PSVersion                      5.1.20348.558
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.558
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

I have tried:

* Checked and Verified TLS 1.2

* Unregistered / Register PSRepository

* Force Update of PackageProvider

* Force Update of PowerShellGet Module

* Checked and Verified internett connection

* Not behind proxy

To anyone who faces the same issue:

The root cause of the issue was the the "Kerberos double hop". You can find different solution in PowerShell Remoting Kerberos Double Hop Solved Securely

After taking care of the "Kerberos double hop", both the Ansible play could execute successfully and Enter-PSSession was able to Find-Script.

alexanderfelipeoines avatar Oct 05 '22 08:10 alexanderfelipeoines

I have found that I only experience the issue if I run the Find-Module command before changing the SecurityProtocol and Proxy setting. I then continue to "always" have the issue. If change the SecurityProtocol and Proxy setting before ever running Find-Module, I do not have the issue.

To explain it a different way:

  1. Launch a new PowerShell instance:
 PS C:\Windows> Find-Module                                                                                                             
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.                                                             
 PS C:\Windows> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12                                         
 PS C:\Windows> (New-Object -TypeName System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials 
 PS C:\Windows> Find-Module                                                                                                             
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.                                                             
 PS C:\Windows>  

:-(

  1. Exit the above PowerShell instance and open another new PowerShell instance:
PS C:\Windows> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Windows> (New-Object -TypeName System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
PS C:\Windows> Find-Module

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
1.0.17               SpeculationControl                  PSGallery            This module provides the ability to query the speculation control settings for the system. 2.2.0.3              PSWindowsUpdate                     PSGallery            This module contain cmdlets to manage Windows Update Client. 
...

:-)

DW-42 avatar Jan 12 '23 00:01 DW-42

Not how to fix this. Open Browser properties app, disable TLS 1.0, press Apply, then Install-Module PSReadLine -Force, then enable TLS 1.0 again.

No issue anymore.

Your strange command forcing TLS 1.2 does not help me.

ValeZAA avatar Aug 18 '23 00:08 ValeZAA

Just went through the same issue, Noticed maybe It was from following the docs for some PowerShell modules on learn.microsoft.com

[Net.ServicePointManager]::SecurityProtocol
(New-Object -TypeName System.Net.WebClient).Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials

Is the fix or work-around. pay attention to learn modules 👍 please make a file management tutorial 😆

berlintay avatar Oct 20 '23 20:10 berlintay

The way I have gotten around this is to simply put this line in your PowerShell scripts.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

snydertl avatar Dec 20 '23 19:12 snydertl

I proved that this was a bug in older version, because disabling TLS 1.0 allows to install new version and then it does not matter, even if you enable TLS 1.0 again.

ValeZAA avatar Jan 01 '24 20:01 ValeZAA