Skip to content

ModuleIntrinsics.GetPSModulePath returns a hard-coded path, rather than the one PowerShell is actually using #24274

@Jaykul

Description

@Jaykul

Prerequisites

Steps to reproduce

Set your user's powershell.config.json PSModulePath

The example here is Windows-specific:

$configPath = Join-Path (Split-Path $Profile) powershell.config.json
if (Test-Path $configPath) {
  $config = Get-Content $configPath | ConvertFrom-Json
  $config.PSModulePath = "%LOCALAPPDATA%\powershell\Modules"
} else {
  $config = @{ PSModulePath = "%LOCALAPPDATA%\powershell\Modules" }
}

$config | ConvertTo-Json | Set-Content $configPath

In a new PowerShell instance:

$Actual = cmd /c "echo %LOCALAPPDATA%\powershell\Modules"
$Api = [Management.Automation.ModuleIntrinsics]::GetPSModulePath('User')
Compare-Object $Api $Actual -IncludeEqual

Expected behavior

GetPSModulePath('User') should return the path the user has configured, so the two values should be the same.

InputObject                                         SideIndicator
-----------                                         -------------
S:\OneDrive - PoshCode\Documents\PowerShell\Modules ==

Actual behavior

InputObject                                         SideIndicator
-----------                                         -------------
C:\Users\Jaykul\AppData\Local\powershell\Modules    =>
S:\OneDrive\Documents\PowerShell\Modules            <=

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions