-
Notifications
You must be signed in to change notification settings - Fork 129
Move PS content out of OneDrive #388
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
base: master
Are you sure you want to change the base?
Changes from all commits
828a981
9901f90
e9808dc
60ee0ab
95798e0
f35150d
e29eb58
239989a
310b1c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
RFC: RFC0066 | ||
Author: Justin Chung | ||
Status: Draft | ||
SupercededBy: N/A | ||
Version: 1.0 | ||
Area: Core | ||
Comments Due: 07/31/2025 | ||
Plan to implement: Yes | ||
--- | ||
|
||
# PowerShell User Content Location | ||
|
||
This RFC proposes moving the current PowerShell user content location out of OneDrive to the | ||
`LocalAppData` directory on Windows machines. | ||
|
||
## Motivation | ||
|
||
``` | ||
As a user, | ||
I can customize the location where PowerShell user content is installed, | ||
so that I can avoid problems created by file sync solutions like OneDrive. | ||
``` | ||
|
||
- PowerShell currently places profile, modules, and configuration files in the user's Documents | ||
folder, which is against established conventions for shell configurations and tools. | ||
- PowerShell content files in OneDrive can lead to unwanted syncing of module files, leading to | ||
various issues. | ||
- There is strong community demand for changing this behavior as the current setup is problematic | ||
for many users. | ||
- Changing the default location would align PowerShell with other developer tools and improve | ||
usability. | ||
|
||
## Specification | ||
|
||
- This will be an experimental feature. | ||
- The content folder location change will only apply to PowerShell on Windows. | ||
- Configurability of the content folder will apply to all platforms. | ||
- A configuration file in the PowerShell user content folder will determine the location of the user | ||
scoped **PSModulePath**. | ||
- By default, the PowerShell user content folder will be located in the | ||
`$env:LOCALAPPDATA\PowerShell`. | ||
- The new location becomes the location used as the `CurrentUser` scope for PSResourceGet. | ||
- The proposed directory structure: | ||
|
||
``` | ||
C:\Users\UserName\AppData\Local\PowerShell\ | ||
├── powershell.config.json (Not Configurable) | ||
└── <PSContent> (Configurable) | ||
├── Scripts (Not Configurable) | ||
├── Modules (Not Configurable) | ||
├── Help (Not Configurable) | ||
└── <*profile>.ps1 (Not Configurable) | ||
``` | ||
|
||
- The following setting is added to the `powershell.config.json` file: | ||
|
||
**UserPSContentPath** specifies the full path of the content folder. The default value is | ||
`$env:LOCALAPPDATA\PowerShell\PSContent`. The user can change this value to a different path. | ||
|
||
```json | ||
{ | ||
"UserPSContentPath" : "$env:LOCALAPPDATA\\PowerShell\\PSContent", | ||
} | ||
``` | ||
|
||
## User Experience | ||
|
||
- On startup PowerShell will create a directory in AppData and a configuration file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it be created empty or with This is essential for the machine config discussed below unless machine-level gets precedence (ideally). User-level precedence and potentially predefined setting in user config would block any machine config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking with the experimental feature turned on UserPSContentPath will be predefined in the config file pointing to the new "recommended" location in LocalAppData. But all of the directories will be empty and the user will have to migrate on their own. As of now for this migration we are thinking about providing an example script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, as long as the machine config setting with variable support takes precedence. 🙂 |
||
- The user scoped **PSModulePath** will point to `Modules` folder under the location specified by | ||
**UserPSContentPath**. | ||
- Users can configure a custom location for PowerShell user content by changing the value of | ||
**UserPSContentPath**. | ||
- Users will need to manually move/copy their existing PowerShell user content from the Documents | ||
folder to the new location after enabling the feature. | ||
|
||
## Other considerations | ||
|
||
- The following functionalities will be affected: | ||
- SecretManagement | ||
- SecretManagement extension vaults are registered for the current user context in: | ||
`$env:LOCALAPPDATA\Microsoft\PowerShell\secretmanagement\secretvaultregistry\` | ||
|
||
When an extension vault is registered, SecretManagement stores the full path to the extension | ||
module in the registry. Moving the PowerShell content to a new location will break the vault | ||
registrations. | ||
- Document instructions on how to re-register vaults after moving the content folder. | ||
- Document the need to keep Modules in the Documents folder to so that SecretManagement | ||
continues to work for multiple installs of PowerShell 7 (stable and preview). | ||
|
||
- Use the following script to copy the PowerShell contents folder: | ||
|
||
```pwsh | ||
$newPath = "C:\Custom\PowerShell\Modules" | ||
$currentUserModulePath = [System.Environment]::GetFolderPath('MyDocuments') + "\PowerShell" | ||
Copy-Item -Path $currentUserModulePath -Destination $newPath -Recurse -Force | ||
``` | ||
|
||
- PowerShellGet is hardcoded to install scripts and modules in the user's `Documents` folder. It | ||
will not support this feature. | ||
|
||
## Implementation questions | ||
|
||
- Will the experimental feature be enabled by default? | ||
- Recommendation: No, the user should explicitly enable the feature and copy their existing | ||
PowerShell user content to the new location. | ||
|
||
- How does `$PROFILE` get populated? | ||
- Can profile scripts be moved to `PSContent`? | ||
- The feature needs to update `$PROFILE` to point to profile scripts in the new location. | ||
|
||
- What happens if **UserPSContentPath** is added to the machine-level configuration file in | ||
`$PSHOME/powershell.config.json`? | ||
- Recommendation: Ignore the setting in the machine-level configuration file since this is a user | ||
setting. No error - just ignore it. | ||
Comment on lines
+114
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent errors often lead to confusion. We should warn somewhere (i.e. Event Log, Write-Warning on launch, etc.). As a system administrator I may want to set this on a shared system where we would want to avoid users ever dealing with OneDrive issues. We should just match the existing precedent defined in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Are you talking about this precedence? If so you're suggesting we make this be default AllUsers unless specified? I'm not opposed to this but am worried about breaking the current setups since they would be forced to migrate all their UserPSContent to the new location. Any thoughts @sdwheeler ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
While I would tend to agree and caution against breaking existing setups, this would only be the case for admins who deploy this setting retroactively. I would prioritize being consistent in how settings are applied and warn admins what the effect of this on the machine level would have. If we're not consistent then we get into the, "Well in this scenario, the precedent comes from X, and in that scenario it comes from Y." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for machine-level preference for consistency and supporting managed/strict environments like shared device and even VDI/VDA where you might place it on a attached user drive.
Not sure if it's done already, but in general there should be an event logged on startup all config-settings with effective value and source (User, Machine, GroupPolicy) as merge/precedence behavior can get complicated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if the following is relevant but I think it'll help with the discussion. I took another look at the PSModulePath code and as of now machine scoped stuff is not in OneDrive but in program files and not in the documents. I think we decided to leave this alone and not move anything out of there. internal static string GetSharedModulePath()
{
#if UNIX
return Platform.SelectProductNameForDirectory(Platform.XDG_Type.SHARED_MODULES);
#else
string sharedModulePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
if (!string.IsNullOrEmpty(sharedModulePath))
{
sharedModulePath = Path.Combine(sharedModulePath, Utils.ModuleDirectory);
}
return sharedModulePath;
#endif
} Will need some clarification from @sdwheeler for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant. Our concern is the user-level modules folder, profile location etc. My understanding is that a In Windows it would be equal to a user configuration in Group Policy, which we can't use here due to cross-platform. |
||
|
||
- Will **UserPSContentPath** support environment variables (like `$env:USERNAME` or `%USERNAME%`)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required to support the machine-wide config at all without mixing user content, isn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think yes the goal is to support environment variables. I think this would be very useful. |
||
- This could enable a global configuration scenario if we allowed configuration in `$PSHOME`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the Linux existing CurrentUser modulepaths, etc. be updated to also use this? Will there be a migration approach? I don't like the idea of disparate paths per OS, should follow the XDG standard for both.
https://specifications.freedesktop.org/basedir-spec/latest/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Linux I'm thinking there is no need to change their existing paths at all. But I do think they would want this customizability.
So a way to achieve this is to add the current modulepaths to powershell.config.json and make the API retrieve the value every time.
For the migration approach, I'm thinking Linux users won't need to do anything if they keep their current path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that on Linux, for example Modules, it's LOCALAppData\PowerShell by default (which dotnet does environment translation to XDG) and on windows it'll now be PowerShell\PSContent, so it'll be inconsistent, and if someone does this setting in a portable way, they'll have to account for those differences.
Is the PSContent folder really necessary? Why not just put Modules/Scripts/etc. in
LocalAppData/PowerShell
directly? Then it's the same path on both Windows and Linux (from a dotnet perspective), plus one less level of unnecessary hierarchy. Is there a problem thePSContent
folder solves?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To demonstrate:

Should be the same "path" in dotnet on both, but land differently in the OS. That way if I change my preferred path, it'll still work consistently. I feel it should also be lowercase on both but if you want to add the appropriate handling for windows so it is PowerShell, that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for dropping PSContent-subfolder as default. Brings consistency with current structure in Documents/PowerShell and other platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added the PSContent folder idea because we are trying to make the location customizable.
To achieve this we want to look at powershell.config to tell us where to look for the PSContent folder which will have everything PowerShell related.
On a side note, I think this also means the location of powershell.config has to be hardcoded and cannot be customized.
Interesting... I didn't know LocalApplicationData dotnet grabbed the linux equivalent like that.
I think Platform.XDG_Type.USER_MODULES already resolves to /home/user/.local/share/powershell
Currently for UNIX we grab the user module path like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍 I expected the config file itself to be hardcoded.
Combined with no automatic content migration when the setting is changed, I don't see any risk of sharing the same powershell-folder for both content and config by default.