diff --git a/src/System.Management.Automation/engine/AutomationEngine.cs b/src/System.Management.Automation/engine/AutomationEngine.cs index 72898d03939..b1e8e6ef889 100644 --- a/src/System.Management.Automation/engine/AutomationEngine.cs +++ b/src/System.Management.Automation/engine/AutomationEngine.cs @@ -35,6 +35,34 @@ internal class AutomationEngine /// internal AutomationEngine(PSHost hostInterface, InitialSessionState iss) { +#if !UNIX + // Update the env variable PathEXT to contain .CPL + var pathext = Environment.GetEnvironmentVariable("PathEXT"); + pathext = pathext ?? string.Empty; + bool cplExist = false; + if (pathext != string.Empty) + { + string[] entries = pathext.Split(Utils.Separators.Semicolon); + foreach (string entry in entries) + { + string ext = entry.Trim(); + if (ext.Equals(".CPL", StringComparison.OrdinalIgnoreCase)) + { + cplExist = true; + break; + } + } + } + + if (!cplExist) + { + pathext = (pathext == string.Empty) ? ".CPL" : + pathext.EndsWith(";", StringComparison.OrdinalIgnoreCase) + ? (pathext + ".CPL") : (pathext + ";.CPL"); + Environment.SetEnvironmentVariable("PathEXT", pathext); + } +#endif + Context = new ExecutionContext(this, hostInterface, iss); EngineParser = new Language.Parser(); diff --git a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 index 750ecfbd518..bfe35cc4c83 100644 --- a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 +++ b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 @@ -564,3 +564,9 @@ Describe "Verify approved aliases list" -Tags "CI" { $result | Should -BeNullOrEmpty } } + +Describe "PATHEXT defaults" -Tags 'CI' { + It "PATHEXT contains .CPL" -Skip:(!$IsWindows) { + $env:PATHEXT.Split(";") | Should -Contain ".CPL" + } +}