Skip to content

Allow pwsh to inherit $env:PSModulePath and enable powershell.exe to start correctly - #11057

Merged
Dongbo Wang (daxian-dbw) merged 10 commits into
PowerShell:masterfrom
SteveL-MSFT:psmodulepath
Nov 16, 2019
Merged

Dongbo Wang (daxian-dbw) merged 10 commits into
PowerShell:masterfrom
SteveL-MSFT:psmodulepath

Conversation

@SteveL-MSFT

@SteveL-MSFT Steve Lee (SteveL-MSFT) commented Nov 13, 2019 •

Copy link
Copy Markdown
Member

PR Summary

Since $env:PSModulePath is shared across all instances of PowerShell, PowerShell 7 needs to ensure it inherits the env var, but put its paths in front. If starting Windows PowerShell, it will special case powershell.exe and powershell_ise.exe removing PowerShell 7 specific paths creating a new environment for the new process.

This is a breaking change as previously, if pwsh detects it is started from PowerShell, it will clear out $env:PSModulePath and create it from scratch. This change will preserve additions from the system or user env vars but not all have the complicated logic in Windows PowerShell. It will always add user module path, shared module path, and $PSHome module path if it's not already there on startup.

PR Context

Fix #9957
Fix #9921
Fix #7082
Fix #6850
Fix #10620

Implement PowerShell/PowerShell-RFC#233

PR Checklist

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Review - Committee The PR/Issue needs a review from the PowerShell Committee Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Nov 13, 2019
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

@PowerShell/powershell-committee reviewed this and agree to accept these changes for Preview.6

@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title Enable Windows PowerShell to run from pwsh Allow pwsh to inherit $env:PSModulePath and enable powershell.exe to start correctly Nov 14, 2019
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
Comment thread src/System.Management.Automation/engine/NativeCommandProcessor.cs Outdated
Comment thread test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Comment thread test/powershell/Modules/Microsoft.PowerShell.Security/certificateCommon.psm1 Outdated
Comment thread test/powershell/engine/Module/ModulePath.Tests.ps1 Outdated
Comment thread test/powershell/engine/Module/ModulePath.Tests.ps1
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs
Comment thread src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Outdated
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

PoshChan-Bot (@PoshChan) please retry windows

@PoshChan

Copy link
Copy Markdown
Collaborator

Steve Lee (@SteveL-MSFT), successfully started retry of PowerShell-CI-Windows

}
}

return string.Join(Path.PathSeparator, modulePathList.ToArray());

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 16, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the .ToArray() call is not needed.
I will resolve this in the web ui.

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 2e55303 into PowerShell:master Nov 16, 2019
@rjmholt

Copy link
Copy Markdown
Collaborator

Why does this close #7082?

@PaulHigin Paul Higinbotham (PaulHigin) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Nov 19, 2019
@ghost

Copy link
Copy Markdown

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

@rjmholt

Copy link
Copy Markdown
Collaborator

FYI this PR did not fix #9921

@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the psmodulepath branch June 6, 2020 02:29
Christopher Degawa (1480c1) pushed a commit to m-ab-s/media-autobuild_suite that referenced this pull request Mar 31, 2022
Issue fixed in PowerShell/PowerShell#11057, released in v7.0.0-preview.6, so available from version 7.0.0
Last Powershell version is 5.1 so 6 was already Powershell Core
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision MustHave

Projects

None yet

5 participants