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 @@ -948,7 +948,11 @@ private static string SetModulePath()
#if !UNIX
// If on Windows, we want to add the System32 Windows PowerShell module directory
// so that Windows modules are discoverable
newModulePathString += Path.PathSeparator + GetWindowsPowerShellPSHomeModulePath();
string windowsPowerShellModulePath = GetWindowsPowerShellPSHomeModulePath();
if (!newModulePathString.Contains(windowsPowerShellModulePath, StringComparison.OrdinalIgnoreCase))
{
newModulePathString += Path.PathSeparator + windowsPowerShellModulePath;
}
#endif

// Set the environment variable...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,30 +324,42 @@ Describe "Import-Module from CompatiblePSEditions-checked paths" -Tag "CI" {
}

Describe "PSModulePath changes interacting with other PowerShell processes" -Tag "Feature" {
BeforeAll {
if (-not $IsWindows)
{
return
$PSDefaultParameterValues = @{ 'It:Skip' = (-not $IsWindows) }

Context "System32 module path prepended to PSModulePath" {
BeforeAll {
if (-not $IsWindows)
{
return
}
Add-ModulePath (Join-Path $env:windir "System32\WindowsPowerShell\v1.0\Modules") -Prepend
}
Add-ModulePath (Join-Path $env:windir "System32\WindowsPowerShell\v1.0\Modules") -Prepend
}

AfterAll {
if (-not $IsWindows)
{
return
AfterAll {
if (-not $IsWindows)
{
return
}
Restore-ModulePath
}

It "Allows Windows PowerShell subprocesses to call `$PSHome modules still" {
$errors = powershell.exe -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
}
Restore-ModulePath
}

It "Allows Windows PowerShell subprocesses to call `$PSHome modules still" -Skip:(-not $IsWindows) {
$errors = powershell.exe -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
It "Allows PowerShell Core 6 subprocesses to call core modules" {
$errors = pwsh.exe -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
}
}

It "Allows PowerShell Core 6 subprocesses to call core modules" -Skip:(-not $IsWindows) {
$errors = pwsh.exe -Command "Get-ChildItem" 2>&1 | Where-Object { $_ -is [System.Management.Automation.ErrorRecord] }
$errors | Should -Be $null
It "Does not duplicate the System32 module path in subprocesses" {
$sys32ModPathCount = pwsh.exe -C {
pwsh.exe -C '$null = $env:PSModulePath -match ([regex]::Escape((Join-Path $env:windir "System32" "WindowsPowerShell" "v1.0" "Modules"))); $matches.Count'
}

$sys32ModPathCount | Should -Be 1
}
}

Expand Down