PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
485 stars 92 forks source link

Import-PSGetRepository fails silently to import UNC based PowerShellGet v2 repositories on PowerShell 5.1 #1442

Closed kborowinski closed 10 months ago

kborowinski commented 11 months ago

Prerequisites

Steps to reproduce

Import-PSGetRepository fails silently to import UNC based PowerShellGet v2 repositories on PowerShell 5.1 (It works on PowerShell 7.3.8)

Steps to reproduce:

  1. Register an UNC PowerShellGet v2 repository (remote PC requried) on PowerShell 5.1:
    Register-PSRepository -Name Test -SourceLocation \\Server\RepoPath -InstallationPolicy Trusted
  2. Try to import the PowerShellGet v2 repository:
    Import-PSGetRepository -Verbose -Force
  3. The UNC repository is not imported:
    Get-PSResourceRepository

Expected behavior

PS C:\> $PSVersionTable

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

PS C:\> Register-PSRepository -Name PowerEdge -SourceLocation \\poweredge\transfer -InstallationPolicy Trusted
Package source with Name: PowerEdge added successfully.
PS C:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PowerEdge                 Trusted              \\poweredge\transfer
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2

PS C:\> Import-PSGetRepository -Verbose -Force
VERBOSE: Found 2 registered PowerShellGet repositories.
VERBOSE: Selected 1 NuGet repositories.
VERBOSE: Registering PowerEdge at \\poweredge\transfer -Trusted:$True -Force:$True.

Name      Uri                       Trusted Priority
----      ---                       ------- --------
PowerEdge file://poweredge/transfer True    50

PS C:\> Get-PSResourceRepository -Verbose

Name      Uri                                      Trusted Priority
----      ---                                      ------- --------
PowerEdge file://poweredge/transfer                True    50
PSGallery https://www.powershellgallery.com/api/v2 False   50

PS C:\>

Actual behavior

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\> Register-PSRepository -Name PowerEdge -SourceLocation \\poweredge\transfer -InstallationPolicy Trusted
Package source with Name: PowerEdge added successfully.
PS C:\> Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2
PowerEdge                 Trusted              \\poweredge\transfer

PS C:\> Import-PSGetRepository -Verbose -Force
VERBOSE: Found 2 registered PowerShellGet repositories.
VERBOSE: Selected  NuGet repositories.
PS C:\> Get-PSResourceRepository -Verbose

Name      Uri                                      Trusted Priority
----      ---                                      ------- --------
PSGallery https://www.powershellgallery.com/api/v2 False   50

PS C:\>

Error details

No error

Environment data

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     1.0.0      Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFileInfo...}

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visuals

No response

SydneyhSmith commented 11 months ago

thanks for reporting @kborowinski this needs investigation

alerickson commented 11 months ago

I wasn't able to repro this. @kborowinski if you open the xml file here: %LocalAppData%\PSResourceGet\PSResourceRepository.xml do you only see the PSGallery registered? If so can you delete this file then try running Import-PSGetRepository -Verbose -Force again?

kborowinski commented 11 months ago

@alerickson:

  1. I see only the PSGallery registered:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <Repository Name="PSGallery" Url="https://www.powershellgallery.com/api/v2" APIVersion="v2" Priority="50" Trusted="false" />
    </configuration>
  2. Deleting the file and executing Import-PSGetRepository -Verbose -Force does not help.

I must stress that this bug happens only on PowerShell 5.1, not on PowerShell 7.3.8 or higher. I've tried this on six different computers now, with the same results (two domain members and two standalone at work, and two at home)

Visuals: Repository

As you can see in the verbose output of command Import-PSGetRepository -Verbose -Force on PowerShell 5.1, it looks like the cmdlet finds two repos but nothing gets registered -> Verbose: Selected NuGet repositories.: image

On PowerShell 7.3.8 it looks like this: image

And for completeness, visuals on the PowerShell 7.3.8: Repository2

If you want me to do any more tests, will be glad to help!

kborowinski commented 11 months ago

@SydneyhSmith @alerickson OK, I've found the issue with Import-PSResourceGet on PowerShell 5.1. and will push a PR later today.

Edit: I've missed your PR request, sorry. If I can suggest a slight change to the proposed PR as there is still a problem with verbose message on PowerShell 5.1