Skip to content

Update setting PSModulePath to concatenate the process + machine env var #11276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 10, 2019

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Dec 6, 2019

PR Summary

The problem is that Windows treats User scope env vars as the preferred value over Machine scope env vars. So if a user has PSModulePath defined in their User scope, then the Machine scope one isn't used. In other words, the Process scope env var is the same as the User scope env var. However, Windows treats PATH differently in that it concatenates PATH from User scope with PATH from Machine scope. PSModulePath works like PATH so it should also do the same thing that Windows doesn't automatically do. You can observe this with just cmd.exe.

The fix here is to start with env var inherited by Process. If it's the same as the one in User scope, it means the user hasn't modified it and it's incomplete, so we append the Machine scope one. If it's different, we just use the Process one.

Also fixed an issue where PSModulePath was a single path without a path separator.

PR Context

Fix #11172

PR Checklist

@SteveL-MSFT
Copy link
Member Author

Codacy is confused about the ternary operator, we should probably update the PSSA rule

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Dec 6, 2019
@SteveL-MSFT
Copy link
Member Author

@PoshChan please retry windows

@SteveL-MSFT SteveL-MSFT modified the milestones: 7.0.0-rc.1, rc.1-consider Dec 6, 2019
@PoshChan
Copy link
Collaborator

PoshChan commented Dec 6, 2019

@SteveL-MSFT, successfully started retry of PowerShell-CI-Windows

…cs.cs

Co-Authored-By: Dongbo Wang <dongbow@microsoft.com>
@daxian-dbw daxian-dbw merged commit 20a236b into PowerShell:master Dec 10, 2019
@SteveL-MSFT SteveL-MSFT deleted the psmodulepath-update branch December 10, 2019 00:25
@daxian-dbw daxian-dbw added CL-Engine Indicates that a PR should be marked as an engine change in the Change Log and removed CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log labels Dec 10, 2019
@ghost
Copy link

ghost commented Dec 16, 2019

🎉v7.0.0-rc.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-Engine Indicates that a PR should be marked as an engine change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modules under C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules not found with PowerShell 7-preview.6
6 participants