-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Let's move PSModulePath out of the documents folder #15552
Comments
A few extra things to consider when putting this up for triage:
I think this change should happen... hopefully soon. I think storage for these modules should be in the PS: I create PowerShell modules... I have a lot of them... and they are all on my OneDrive now. 😒 |
@jeroenlandheer Do you mean Update-Module? If so you couls discuss in PowerShellGet repository. |
@iSazonov Would the PowerShellGet guys be able to change the default value of Though there should probably be a second issue in PowerShellGet to respect the value, not overwrite it. |
@JohnLudlow Any changes related to PSModulePath are breaking changes. We need to keep backward compatibility. |
@iSazonov Sorry, that was a typo. This should indeed go there too, but don't you think they will choose the location of the modules where they install them... based on whatever this teams says it should be? (AFAIK there's no way to customize this with settings, but that's something for another day.) If paths for loading the modules is the primary function of
No need to move stuff around, new things get installed in And now we're on this subject, in Windows installations, modules which are installed on the local machine are installed by default in the AFAIK the functionality of Hope this helps. |
@jeroenlandheer Indeed, and if I do want to move the older modules to the new folder (I probably would, in my case), there are some options:
Any of those would work for me, but some people may appreciate it being done for them. And you're absolutely correct IMHO about the Windows Modules. The only modules that should be there are ones that are installed as part of PowerShell and shouldn't be removed. |
While I agree that it would be hard to claim this is explicitly a breaking change of an API, it would still be disruptive. There has never been a supported way of determining the module paths of different scopes, e.g. no (Note that I'm not necessarily advocating against it, but it's something that needs to be considered) |
Related: #7082 (comment) |
Previously discussed in #8069 too |
So we reviewed this on the @PowerShell/powershell-committee today, but also this is something I've personally done some thinking on in the past. The mangling on particular locations on the PSModulePath is something we've seen users impacted by repeatedly. For example: PowerShell/vscode-powershell#2824 (comment). Another important point is that the CurrentUser and AllUsers module paths are actually configurable in the powershell.config.json: PowerShell/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Lines 1304 to 1305 in e2c23fc
So there is a concept of both the default CurrentUser module path and the actual one. However, there's currently no way to communicate the actual one, so the default is the implicit contract between PowerShell's module system ( Today it seems that both PowerShell 7 and PowerShellGet agree that the default CurrentUser module path lies under the The big issue now is that OneDrive configurations override the MyDocuments folder and cause this unexpected migration. But additionally, the actual CurrentUsers module path could be overridden with a configuration. And this is something that things like the PowerShell Azure Functions worker would want to do given the radically different environment in which it operates. Except that there's no way for PowerShellGet to pick this up. In terms of changing the default PSModulePath, there have been a lot of proposals to fix PSModulePath in various ways. Changing the CurrentUser path away from MyDocuments is going to break PowerShellGet, since it depends on the same location being used. However, the MyDocuments path clearly presents problems, and both the proposed alternatives ( So in terms of recommendations:
|
@rjmholt That's a great summary. Thanks. We'll see what the Engine Working Group say |
With behavior of OneDrive the WG agrees that we need to come up with a proper solution, however the scenarios have a high level of complexity which is exacerbated by the need that other PS tools also need to be able to use whatever solution is made available. The WG proposes that PS should provide an API which allows tools to query for the default location of modules. The tool chain also needs to be able to query PS so the values are consistent. We propose that an RFC is needed to define the behaviors, not only for PowerShell proper but for tools like PowerShellGet. We think at least the following requirements need to be addressed in the RFC:
|
+1. Nuget doesn't have this problem because it uses It's like syncing a .git repo in OneDrive! Unnecessary. Whichever solution comes up, it should be configurable for devices, i.e. via InTune or PowerShell so we can make it consistent for all our developers. |
Would a dot folder work here possibly? i.e. I came across this as I'm looking to considerably cut down my documents folder when looking at OneDrive backup and I was hoping there was a way I could have PSGet use another folder. I'm still looking into what my options for this are - not sure if just changing |
@mikhey Changing A |
My preference is Also, I notice that many other tools on Windows are now using |
@JohnLudlow yeah, I was thinking of making it a symlink, but OneDrive doesn't like that for the backups. After I realized that I had much more space than I thought it did, I just let it go to OneDrive. While it may have become a non-issue for me regarding OneDrive, I do feel it is something that should be addressed. This has probably been mentioned before, but off the top of my head a few things to look at for an implementation could be:
|
As @rkeithhill said, those dot folders pollute PowerShell actually already conforms to the XDG base directory specification on *nix, which is a standard intended to solve this problem. PowerShell data files, including modules, are stored in The issue then is that Windows doesn't really offer a clear answer here, because its philosophy is to separate users from configurers/application installers. Worth noting is that the XDG standard is configurable with a sensible default, and I imagine we want the same, we just need to weigh configurability against complexity (mainly for anyone developing against our decision) and performance. |
@rkeithhill and dot files are supposed to also be hidden, but Windows is not linux so dot files are left always visible. So I'd like to add my voice here in asking to please respect the platform conventions on Windows and use the appropriate AppData folder, and in the same way use XDG on Linux and whatever macOS specifies for it's convention. As for accessibility for profile editing, I think that's already covered by using At most adding a |
I'm just stopping by to express my frustration with how things are today. I'm happy to read about positive discussions for change, though! Trying to update To workaround this, you need to update your MyDocuments (aka 'Personal') folder to no longer be in the OneDrive folder. This seems to work well for me:
Figured I'd share this in case anyone needed it /shrug |
Just to plus one on the pain and urgency here. I just lost half a day trying to figure out exactly the issue @jeroenlandheer mentioned back on June last year, namely trying to Update-Module on a machine fails because I installed the module on a difference machine, and both are sync'ing my documents via OneDrive. Beside the issue above this causes, I'm now syncing over 900MB of PowerShell files to my OneDrive account, and I only have two modules installed! (The 'Az' and the 'Microsoft.Graph' modules - which I suspect are in common usage). I'm probably just going to stop using OneDrive or install for AllUsers, but it was time consuming and frustrating to figure this out. |
Agreed - without this, Controlled Folder Access would still block the installation of all modules that make use of that folder (for example, https://github.com/PowerShell/SecretManagement). |
Not every powershell users needs a dev drive however, there are several people tasked with just running scripts all day, everyday. |
@bwilsonms of course, that would be just one of many reasons why this would be desirable. |
It's now 2024. @SteveL-MSFT, @JohnLudlow, @iSazonov, @rkeithhill, Et al. How do we keep this moving forward? It's been almost 3 years and while there seems to be consensus on the need, there does not seem to be any tangible progress toward fixing the problem. This issue was tagged with milestone, 7.4 but that has passed. There were also several past comments about needing an RFC, but I never saw where one was started (What does RFC even mean in the context of a PowerShell setting?), and if it did can some point the way to where that work is being done? I know this a considered a breaking change, but it can also alleviate a previous breaking change introduced by Controlled Folder Access (see post here) that many of us are having to work around on a daily basis. We need this in 2024 and ideally in 7.5. |
As a workaround, ModuleFast installs to your LocalAppData by default and automatically sets up everything for you to make it work. https://github.com/justingrote/modulefast
|
As it stands now I consider this a breaking experience as it is. We have our Documents folders redirected and scripts take forever to finish because of the constant searching for modules in our network folders. |
It comes from very old decision way back in old PowerShell before OneDrive was even a concept. Can't predict the future :) |
I think this is some sort of Microsoft sickness. Some decision is made early on (place stuff in "system32" folder). Then things change, or this is no longer a great idea (stuff should be in "system64" logically). But since other developers didn't actually read Microsoft's best practice guide, they hardcode the value. Then Microsoft for some reason goes out of their way to retain compatibility with all Windows versions ever released, making things ever more unintuitive.
Just make the change when it's needed. Maybe get some guys from the Microsoft naming department, they seem to like making changes? Though then you'll probably run in to the "path to long" problem... |
Which is why it is so important to stick to the OS guidelines and put that stuff in LOCAL APP DATA, instead of dreaming up new locations that WILL break things when new features are introduced, like OneDrive. |
Is there a way for a user to opt-out of OneDrive being added to PSModulesPath every time? Can we add a setting somewhere? It should be easy to add a setting and keep the old behavior by default. |
It's not OneDrive that gets added, it's the Documents folder path that onedrive is redirecting. The "simple" solution is to not redirect your My Documents to OneDrive, and just use OneDrive separately as a separate folder, there aren't any "good" alternatives that don't result in a lot of errors and I've tried a lot (symlinking, hardlinking, regedits, excludes, you name it). |
Can we add an option that adds a custom user-specified directory instead of Documents? |
or better yet doesn't add anything at all and relies purely on the PSModulesPath environment variable? |
That already exists, unfortunately it has to be done in a I requested that path be exposable but that was closed in favor of this issue: And PowerShellGet My
|
is there a bug to support this setting in Install-Module? |
|
I have successfully used symlinks to solve OneDrive for hundreds of users. Documents was redirected to OneDrive by policy. We created a folder in the user profile, moved modules there incrementally, and symlinked modules individually into Docs/blah/Modules. Modules can be moved on the fly, even if there are locked DLLs, with |
@fsackur pretty sure onedrive still complains of a sync conflict when you do this and there was no way even with exclusions to suppress it, unless something's been updated since I last attempted. |
@rkeithhill I agree it becomes an issue for users that don't have the setting to see hidden folders. That said the I'm liking the |
OneDrive follows symlinks/junctions without errors on the latest versions (tested on MSIT Fast, Insider, and prod), but the status on files/folders is syncing even when sync has completed. I've been storing There's a new setting to exclude folders by name and ADMX/ADMLs, but it doesn't activate even when using the example values. The file-based exclusion setting works with similar values. ProcMon shows |
RIght, it's that constant "syncing" status that I'm referring to, it's not seamless for casuals. |
I would argue ideally users don't need to ever see the modules folder except for advanced troubleshooting, similar to the registry, and only interface with it using the install/update/uninstall commands indirectly. |
@pl4nty Can you please elaborate? Which Windows/OneDrive version are you using? |
Factually incorrect. AppData is and has been the location to store application data and configuration (besides the registry) for over 30 years. It's only today that more and more inexperienced Windows developers starting abusing the profile folder to place configuration data, because they're used to macOs or Linux. As a sysadmin, I've migrated countless user profiles to new computers over the past decades and can tell you from experience, that most software (or at least the ones adhering to the standard) put their settings into AppData (or the registry).
Furthermore: https://learn.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=net-6.0 |
Powershell is an application. Modules are application data. Therefore that's where modules should go (Appdata) instead of documents, and "allusers" modules should go into I don't see anything here that counters that point. Maybe you misunderstood what I was saying? |
@ALIENQuake currently OneDrive 24.086.0428.0003 on Windows 10.0.22631.3527 |
@pl4nty Well, ive tried and I'm still seeing "The 'ExampleFolderJunction' in Documents is junction point ..." error which prevents me from syncing Documents folder. Same for latest insider. Thanks for help anyway, I won't nagg you about this anymore. |
I agree that modules, like other application data, should be placed within (Local)AppData or ProgramData. I misunderstood your argument as advocating for placing these files inside a dot-folder within the user profile. |
Summary of the new feature/enhancement
The documents folder has always been where modules user-scoped are kept, and that's always been ok, but I recently discovered some problems with this as I've been getting more familiar with Azure and my work laptop maps Documents to OneDrive. This can be problematic for a few reasons, such as OneDrive not syncing correctly or trying to restore a bunch of files from a module I just uninstalled. This is particularly an issue with larger modules (or groups of modules) such as Az.*
We can certainly wish OneDrive was better at its job, but really these files shouldn't be there - they are not documents. The user is not expected to edit them or look at them. They are more akin to application files or application data. There's no value to them being in OneDrive other than to transfer them to another machine, and that can be better achieved by having a script in OneDrive that calls PSDepend or PowerShellGet to install modules on that other machine.
I have updated my profile script to remove this path but it reappears after running
install-module
.Proposed technical implementation details (optional)
Documents\PowerShell\Modules
from the$env:PSModulePath
default. Select a new default path such as~\PowerShell\Modules
or$env:localappdata\PowerShell\Modules
The text was updated successfully, but these errors were encountered: