Skip to content

Get-PSResource treats multiple paths set in the environment variable PSModulePath as a single path #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
steveharsant opened this issue Sep 24, 2021 · 2 comments · Fixed by #541
Closed
3 tasks done
Assignees
Labels
Area-Paths Issue-Bug Something isn't working
Milestone

Comments

@steveharsant
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

When executing Find-PSResource on PowerShell Core and 5.1 the $env:PSModulePath is treated as if it is a single path when it contains multiple paths for the different installation scopes.

For example:

PS /> Get-PSResource
Get-PSResource: Could not find a part of the path '/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules'.

PS /> dir env:
Name                           Value
----                           -----
PSModulePath                   /root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules

The workaround is to set $env:PSModulePath with a single path and retry. For example:

PS /> $env:PSModulePath = '/root/.local/share/powershell/Modules'
PS /> Get-PSResource

Name          Version      Repository
----          -------      ----------
PowerShellGet 3.0.0-beta10 PSGallery

Expected behavior

PS /> Get-PSResource

Name          Version      Repository
----          -------      ----------
PowerShellGet 3.0.0-beta10 PSGallery

Actual behavior

PS /> Get-PSResource
Get-PSResource: Could not find a part of the path '/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules'.

Error details

Exception             :
    Type       : System.IO.DirectoryNotFoundException
    TargetSite :
        Name          : CreateDirectoryHandle
        DeclaringType : System.IO.Enumeration.FileSystemEnumerator`1[TResult]
        MemberType    : Method
        Module        : System.IO.FileSystem.dll
    StackTrace :
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1.Init()
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.UserDirectories(String directory, String expression, EnumerationOptions options)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.Directory.GetDirectories(String path)
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.GetHelper.ProcessGetParams(String[] name, String version, Boolean prerelease, String path)
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResource.ProcessRecord()
   at System.Management.Automation.Cmdlet.DoProcessRecord() in /PowerShell/src/System.Management.Automation/engine/cmdlet.cs:line 173
   at System.Management.Automation.CommandProcessor.ProcessRecord() in /PowerShell/src/System.Management.Automation/engine/CommandProcessor.cs:line 388
    Message    : Could not find a part of the path '/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules'.
    Source     : System.IO.FileSystem
    HResult    : -2147024893
CategoryInfo          : NotSpecified: (:) [Get-PSResource], DirectoryNotFoundException
FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.PowerShellGet.Cmdlets.GetPSResource
InvocationInfo        :
    MyCommand        : Get-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 18
    Line             : Get-PSResource
    PositionMessage  : At line:1 char:1
                       + Get-PSResource
                       + ~~~~~~~~~~~~~~
    InvocationName   : Get-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     3.0.0      beta10     PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Install-PSResource…}

Key   : PSVersion
Value : 7.1.4
Name  : PSVersion


Key   : PSEdition
Value : Core
Name  : PSEdition


Key   : GitCommitId
Value : 7.1.4
Name  : GitCommitId


Key   : OS
Value : Linux 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020
Name  : OS


Key   : Platform
Value : Unix
Name  : Platform


Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions


Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion


Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion


Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Visuals

N/A

@StevenBucher98
Copy link
Collaborator

Thanks for bringing this to our attention @steveharsant, do you mean to say Get-PSResource in your title and description? We have marked it as a bug and will investigate further.

@steveharsant steveharsant changed the title Find-PSResource treats multiple paths set in the environment variable PSModulePath as a single path Get-PSResource treats multiple paths set in the environment variable PSModulePath as a single path Sep 30, 2021
@steveharsant
Copy link
Author

steveharsant commented Sep 30, 2021

Thanks for bringing this to our attention @steveharsant, do you mean to say Get-PSResource in your title and description? We have marked it as a bug and will investigate further.

@StevenBucher98 yes. Apologies. I meant Get not Find! Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Paths Issue-Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants