Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ internal static string GetModulePath()

#if !UNIX
/// <summary>
/// Returns a PSModulePath suiteable for Windows PowerShell by removing this PowerShell's specific
/// Returns a PSModulePath suiteable for Windows PowerShell by removing PowerShell's specific
/// paths from current PSModulePath.
/// </summary>
/// <returns>
Expand All @@ -1261,9 +1261,24 @@ internal static string GetWindowsPowerShellModulePath()
var modulePathList = new List<string>();
foreach (var path in currentModulePath.Split(';'))
{
if (!excludeModulePaths.Contains(path))
var trimmedPath = path.Trim();
if (!excludeModulePaths.Contains(trimmedPath))
{
modulePathList.Add(path);
// make sure this module path is Not part of other PS Core installation
var possiblePwshDir = Path.GetDirectoryName(trimmedPath);

if (string.IsNullOrEmpty(possiblePwshDir))
{
// i.e. module dir is in the drive root
modulePathList.Add(trimmedPath);
}
else
{
if (!File.Exists(Path.Combine(possiblePwshDir, "pwsh.dll")))
{
modulePathList.Add(trimmedPath);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@ Describe "PSModulePath changes interacting with other PowerShell processes" -Tag
$errors | Should -Be $null
}

It "Allows Windows PowerShell subprocesses to load WinPS version of `$PSHOME modules" {
powershell.exe -Command "Get-ChildItem | Out-Null;(Get-Module Microsoft.PowerShell.Management).Path" | Should -BeLike "*system32*"
}

It "Allows PowerShell subprocesses to call core modules" {
$errors = & $pwsh -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
Expand Down