Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Install-Module should default to CurrentUser #236

Closed

Description

I add a default parameter for Install-Module to set Scope to CurrentUser wherever I use the command. I explicitly set the scope to CurrentUser when I use it in build scripts (CI tooling).

I believe the default install location should be CurrentUser. A system level change should only occur when explicitly requested.

Expected Behavior

Modules installed using Install-Module should be placed in CurrentUser scope unless I explicitly request AllUsers scope.

Current Behavior

Modules installed using Install-Module attempt to install into AllUsers scope, I must explicitly request the less broad scope.

Possible Solution

The current default for the Scope parameter should be changed to CurrentUser:

https://github.com/PowerShell/PowerShellGet/blob/development/PowerShellGet/PSModule.psm1#L1962

Activity

  1. markekraus commented on Mar 1, 2018

    @markekraus

    I have this set as a default parameter in my profiles too. I don't have a single line of code anywhere that depends on the ability to install system level modules. Aside from the core PowerShell modules and those provided by Windows/RSAT, all of my automation and code rely on CurrentUser scoped modules. The only time use AllUsers is when I run Install-Module on a system without my profile settings and forget that CurrentUser is not the default. In other words, I only use this scope on accident and never intentionally.

    I cannot fathom a reason to have AllUsers as the default scope. Especially since this requires elevation.

  2. nonameneeded commented on Mar 1, 2018

    @nonameneeded

    This would be awesome!

  3. bergmeister commented on Mar 1, 2018

    @bergmeister
    Contributor

    This would not be awesome because I am sure many people forget to specify to use AllUsers scope when installing stuff on CI machines. Because most CI user accounts are non-interactive, it is common practice to remote to the machine and do the installation using an admin account.

  4. markekraus commented on Mar 1, 2018

    @markekraus

    Christoph Bergmeister (@bergmeister) I'm not sure I follow that logic. In every CI scenario I have seen, CurrentUser is having to be set explicitly and that there is no assumption that the required modules will be available in the CI environment. Are you saying that it's more common to have the CI environment preloaded with modules at the system level?

    It's pretty clear this would be a breaking change. It's just one I think is worth making.

  5. bergmeister commented on Mar 1, 2018

    @bergmeister
    Contributor

    Mark Kraus (@markekraus) The CI systems that I work with are often heavily locked down and managed by our DevOps department (they want to ensure that the build servers only build and nothing else) but we also have complex system tests where around 10 different accounts are being used to test various integration scenarios.

  6. tommymaynard commented on Mar 1, 2018

    @tommymaynard

    If we think of PowerShell modules as applications, and I think in some respects we can, we begin to appreciate the fact that they're out to benefit the greatest number of people they can on a single system. I wouldn’t be surprised if this was the reason for the AllUsers scope default, and why many application installers default to "C:\Program Files\" or "C:\Program Files (x86)\," vs. "C:\Users\username\AppData\." I’m looking at you, virus writers, as they understand the value of defaulting to a location where the user most certainly has permissions to write. Maybe installing modules should be an administrative task.

    Maybe I can be swayed, but I lean toward to leaving it as it is. Initially, I have to wonder if it may be too big a breaking change, and that others -- that expect it work the way it does now -- would only end up trading places.

    Probably not possible, but knowing how the Install-Module command was executed more often (AllUsers vs. CurrentUser), when it is run against the PowerShell Gallery, would be some great information to see. Sure, I get the command has a default, so it may not be a fair test. Maybe the parameter should be mandatory, and not have a default value. Or maybe, we should stop trusting the defaults. I write all my non-single use commands, with all the parameter and parameter values I want included, whether or not, they’re default. You never know when someone’s going to come along and try to change the defaults. ;) I don’t know the next person to read my code, but maybe they won’t consider the default parameters and parameter values. A complete command means that it’s not a requirement they do.

    Now, maybe what I would get behind more, is a fallback: AllUsers is default; however, if Install-Module fails to write to "C:\Program Files\WindowsPowerShell\Modules," for instance, it should default to the CurrentUser location. I do this sometimes in my coding. You could check the permissions at the Save location, or do like I’ve done a time or two (and be lazy), and write a temporary file there. If it works, delete the temporary file and proceed. If it doesn’t, alert the user (potentially), and save to the CurrentUser save location.

    Just some thoughts.

  7. markekraus commented on Mar 1, 2018

    @markekraus

    I write all my non-single use commands, with all the parameter and parameter values

    Right and that's not the issue. The issue is when you are doing this as a user for your own uses. If a user is on a system where they are not the administrator, the default action is confusing. Nearly all of the documentation for installing a module with Install-Module without the -Scope present. This prompts a very frequent question on forums, slack, and github repos "How can I install modules form the gallery without admin rights?" IMO, this design decision breaks the principle of least astonishment.

    I don't think of modules as "applications" and in fact, at the last community call it was made clear that they shouldn't be used as such and that the PSGallery was not to be used for application deployment. I think of them as extensions to MY code, not the system's code, but MY code (where "MY" may not literally be me, but the task runner, automation job, microservice, etc). Since it's extending MY code, it should be in MY environment by default. if it's in my profile, that can (potentially) migrate with me. If it's in the system, I have to reinstall it on every system I run MY code.

  8. vexx32 commented on Mar 1, 2018

    @vexx32

    Perhaps a simpler change is required, then.

    Instead of an outright error, warn users that do not have administrative rights that they can install a module just for themselves using -Scope CurrentUser if they wish, otherwise administrative rights are required.

  9. markekraus commented on Mar 1, 2018

    @markekraus

    The problem still remains that I do not think the default behavior that most desire is to install modules at the system level. I'm still on board for making that clear via warning or error. But when I have -Scope CurrentUser in over 30 automation scripts and in $PSDefaultParameterValues['Install-Module:Scope'] = 'CurrentUser' my profiles on 7 different machines, and have never once wanted to install a module at the system level.... I have to question the default behavior.

  10. bergmeister commented on Mar 1, 2018

    @bergmeister
    Contributor

    Wouldn't it be cleaner to have 2 dedicated cmdlets: Install-ModuleForCurrentUser and Install-ModuleForAllUsers. It looks ugly at first but it is right in the face of the user so that they know what they are about to do. A cmdlet should, like a GUI, be only a very thin layer/wrapper to its underlying methods anyway.

  11. markekraus commented on Mar 1, 2018

    @markekraus

    I don't think having 2 cmdlets that do the same thing is cleaner. I think keeping the same cmdlet and changing the default behavior is cleaner, even though it is a breaking change. IMO, this is bad design from the start and we shouldn't have to suffer bad design just because correcting it is a breaking change.

  12. tommymaynard commented on Mar 1, 2018

    @tommymaynard

    Both of your paragraphs were convincing Mark Kraus (@markekraus), almost as if they should've been included on the first pass. Since you mentioned it, I do recall being one of those users. I also had a pause at being unable to download and install a module from the PSGallery with the default command. Ugh... so now I'm little more torn on whether or not the default should be changed -- good arguments. So, maybe we've long needed a C:\Users\Public\Documents\WindowsPowerShell\Modules\ directory.

  13. bergmeister commented on Mar 1, 2018

    @bergmeister
    Contributor

    What about having to specify a mandatory parameter with the type of installation then. Defaults are opinionated and can often be bad (although I usually advocate that stuff should work out of the box without having to specify loads of parameters)

  14. markekraus commented on Mar 1, 2018

    @markekraus

    Christoph Bergmeister (@bergmeister) I'm ok with a mandatory parameter... but.. then there will be a massive amount of documentation and examples that will no longer work... not that I think that is a reason to avoid doing this, but if one of my motivations is to decrease new user questions related to Install-Module, then a mandatory parameter change might have the opposite affect as a result of ingrained documentation practices.

  15. bergmeister commented on Mar 1, 2018

    @bergmeister
    Contributor

    What if it used currentuser when not being elevated but only prompts to specify the type when being elevated?

  16. 20 remaining items

  17. markekraus commented on Mar 7, 2018

    @markekraus

    Ryan Yates (@kilasuit) It's actually been suggested previous in the issue.

    I think there is a great potential for that behavior to break the Principle of Least Astonishment. Though, I suspect the users who will be affected by that may already being explicitly supplying it anyway.

  18. rkeithhill commented on Mar 11, 2018

    @rkeithhill

    Adding to Ryan Yates (@kilasuit) suggestion:

    If it running in a non-elevated state - default to CurrentUser (as the AllUsers Scope requires elevation to install to) but also provide user input to inform that this is the action that is happening (non-interactively)

    I'd tweak this a bit and suggest that in this scenario, the command inform the user that they have to be running as admin to install modules into the "default" AllUsers location. If they would like to proceed and install the module only for the current user, press Y (or N to cancel). Then add some helpful text like: "In order to avoid this prompt in the future, run from an elevated context to install modules for all users or supply the parameter -Scope CurrentUser". That, or -Confirm:0. And for extra credit, provide a prompt option to remember the user's choice and do not prompt again.

    There is a concern with prompting but A) you should be able to check for non-interactive mode and B) this scenario would error anyway. The non-interactive case would just fail as it currently does.

  19. SteveL-MSFT commented on Mar 23, 2018

    @SteveL-MSFT
    Member

    I don't own this module, but I'll add my 2c as a user. In general, we should not require elevation/sudo where it's not absolutely required. In this case, I think it makes sense it should have been CurrentUser as the default, but breaking changes should not be taken lightly. If we think 5-10 years from now, I would expect that the majority of users will be frustrated that they have to add -Scope because it fails the first time they run it.

    Adding heuristics whether the user is elevated or not will lead to confusing mistakes in my opinion.

  20. rkeithhill commented on Mar 23, 2018

    @rkeithhill

    we should not require elevation/sudo where it's not absolutely required

    Totally agree.

    but breaking changes should not be taken lightly

    Agreed but in this case how badly breaking is this really? The module should still install - just for the current user rather than all users. Do scripts that install modules really care if a module is only installed for the current user? I can only speak for myself in which case, no. My scripts run for me and on build systems where, if the module is installed for the current user, that is good enough. Then again, I don't write scripts to provision new PCs and servers. Maybe this is more important in that scenario.

    If we think 5-10 years from now, I would expect that the majority of users will be frustrated that they have to add -Scope because it fails the first time they run it.

    You don't have to wait 5-10 years from now. They've been frustrated ever since v5 shipped. :-)

  21. kilasuit commented on Jun 5, 2018

    @kilasuit

    this was raised initially in #2 and really should have been fixed then

  22. Jaykul commented on Jul 11, 2018

    @Jaykul

    I think that the root complaint here is about the process of installing -- not about where it installs and whether it's available to all users or not.

    For the vast majority of people to be happy, all that's really needed is for Install-Module to fork an elevated process to do the install, instead of failing.

    We would get simple install (for most people, just click yes on the UAC prompt), without compromising on either the "security" of having modules installed to a protected location, or the "functionality" of having modules installed to a shared location.

    Everything could stay the way it is, default-wise -- and the only time you'd have a problem is when you were setting up (non-interactive) automation to install things. In that case, you can explicitly opt-in to the user install location, or rethink your automation plan and separate install from whatever else you're doing

  23. edyoung commented on Aug 23, 2018

    @edyoung
    Contributor

    See pull request #315 which implements the suggestion by Ryan Yates (@kilasuit) . FYI alerickson

  24. bmanikm commented on Sep 10, 2018

    @bmanikm
    Contributor

    #315 Implements below functionality
    PS 3.0/4.0/5.0/5.1 : Default scope is based on the current user privileges.
    PS Core 6+: Default scope is always CurrentUser (it includes Windows as well).
    Users can still specify the -Scope parameter if they would like to install to the required scope path.

  25. bmanikm commented on Sep 13, 2018

    @bmanikm
    Contributor

    Resolved with #315.

  26. TomBonnerAtTFL commented on Sep 13, 2018

    @TomBonnerAtTFL

    Don't suppose we could ask for some clarity on the sudden perspective change @ Microsoft on this issue? This was issue #2 on this repo since 2016 and @JKeithB made it sound here as though the behaviour wasn't going to change. I think it's a great change to see though, so thank you.

  27. kilasuit commented on Sep 13, 2018

    @kilasuit

    Tom Bonner (@TomBonnerAtTFL) essentially there were lots of conversations happened with a number of MVP's like myself and the team to push this change through as well as issues like this

  28. edyoung commented on Sep 13, 2018

    @edyoung
    Contributor

    It's not really that there has been a sudden change - there's been a lot of spirited debate on this one both online and offline. We gradually came round to this being the best path forward.

  29. edyoung commented on Nov 27, 2018

    @edyoung
    Contributor

    To restate the design rationale for the new behavior as of 2.0:

    The main desire here is to make Install-Module more convenient when running interactively: on all platforms, you should not run as an elevated user all the time, and it is annoying to have to specify -Scope CurrentUser all the time to avoid an error. As desired, now if you don't specify the scope, Install-Module should succeed on all platforms whether you are elevated or not.

    However we're concerned that there may be scripts that people run under a system account in order to provision packages which will then be run by other users - we know from other issues that have been raised that people want to register repositories that are usable by other users. So we did not change the behavior when running as an elevated account in Windows PowerShell only - that still installs for all users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions