PowerShell / PowerShellGallery

228 stars 65 forks source link

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

Open pbuffolino opened 3 years ago

pbuffolino commented 3 years ago

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

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

alerickson commented 3 years ago

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.

Saved-by-Him commented 3 years ago

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

SydneyhSmith commented 3 years ago

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.

pbuffolino commented 3 years ago

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!

Saved-by-Him commented 3 years ago

[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 commented 3 years ago

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

alerickson commented 3 years ago

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

Saved-by-Him commented 3 years ago

@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

[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 commented 3 years ago

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

SydneyhSmith commented 3 years ago

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

Saved-by-Him commented 3 years ago

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>>

mderouen commented 3 years ago

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

Set TLS to 1.2

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

Liturgist commented 3 years ago

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.
QuadmanSWE commented 3 years ago

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
reuvenab commented 3 years ago

Experienced same problem with Powershell 7.1.4 image

Solved it using "regular" Powershell 5.1 image

Liturgist commented 3 years ago

Experienced same problem with Powershell 7.1.4

Solved it using "regular" Powershell 5.1

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

adityapatwardhan commented 3 years ago

@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

abatishchev commented 3 years ago

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.

jwittner commented 2 years ago

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.

stinos commented 2 years ago

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!

brianary commented 2 years ago

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.
SwimmeRM commented 2 years ago

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... ;-)

choukimasri commented 2 years ago

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"
alexanderfelipeoines commented 2 years ago

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

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:

alexanderfelipeoines commented 2 years ago

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.

DW-42 commented 1 year ago

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. ...


:-)
ValeZAA commented 1 year ago

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.

berlintay commented 11 months ago

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 😆

snydertl commented 9 months ago

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

ValeZAA commented 9 months ago

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.