Skip to content

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

Closed
@steveharsant

Description

@steveharsant

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions