Add PSContentPath Standard Platform Paths#1912
Open
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This pull request introduces support for the PowerShell "PSContentPath" experimental feature, allowing users to customize the location of user content (such as modules and scripts) via an environment variable or configuration file. The code now prefers these new paths when the feature is enabled, improving flexibility and future compatibility.
Support for PSContentPath experimental feature:
powershell.config.json).PSUserContentPathin the environment variable or configuration file, using it as the base path for user content if it exists. If not set, it defaults toLocalApplicationData\PowerShell.MyDocuments\PowerShellfolder for user content.Refactoring and path resolution:
GetPathsFromEnvVarAndScopeto use the newpsUserContentPathvariable instead of the legacy documents path, ensuring the correct directory is used based on feature detection.Utility methods:
IsExperimentalFeatureEnabled(to check for enabled features in the config) andGetPSUserContentPath(to retrieve the custom user content path from environment or config).PR Context
This change introduces support for the PowerShell PSContentPath experimental feature, enabling users to customize where PowerShell stores user content (modules, scripts, etc.). Historically, PowerShell has relied on fixed paths such as MyDocuments\PowerShell, which limits flexibility in modern environments. With this update, users can define a custom content path via an environment variable or configuration file, allowing PowerShell to adapt to diverse deployment and security scenarios.
The feature is a direct response to long-standing community feedback (see PowerShell/PowerShell#15552) and aligns with related work in #1912. It was shaped through detailed specifications in PowerShell/PowerShell-RFC#388. This milestone lays the foundation for flexible, user-configurable content storage, addressing needs such as:
Roaming profiles
Containerized environments
Read-only file systems
By introducing this capability, we empower users to tailor PowerShell to modern deployment and compliance requirements.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.