You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
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:
Reacted by Thomas Rayner, Mark Kraus, Chris Gardner, vrdse, Patrick Meinecke, Chase Freeman, Andrew Childs, Dave Britten, halvarsson, Spyingwind and 26 more
Reacted by Christoph Bergmeister, oldlost, Kris Borowinski, Elle and Joel Bennett
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.
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.
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.
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.
Reacted by Mark Kraus, tommymaynard, oldlost and Kris Borowinski
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.
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.
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.
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.
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.
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.
Reacted by Patrick Meinecke, Elle, Brandon Olin, Rick-2CA, Keith Hill, Aaron and Chris Magnuson
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.
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)
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.
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.
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.
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.
Reacted by Mark Kraus, Chris Dent, Rain Sallow (/u/ta11ow) and Shayde Nofziger
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. :-)
Reacted by Mikey Lombardi (He/Him), Steve Lee, Rain Sallow (/u/ta11ow) and Spyingwind
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
#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.
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.
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
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.
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.
Activity
markekraus commentedon Mar 1, 2018
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
AllUsersis when I runInstall-Moduleon 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.
nonameneeded commentedon Mar 1, 2018
This would be awesome!
bergmeister commentedon Mar 1, 2018
This would not be awesome because I am sure many people forget to specify to use
AllUsersscope 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.markekraus commentedon Mar 1, 2018
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.
bergmeister commentedon Mar 1, 2018
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.
tommymaynard commentedon Mar 1, 2018
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.
markekraus commentedon Mar 1, 2018
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-Modulewithout the-Scopepresent. 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.
vexx32 commentedon Mar 1, 2018
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 CurrentUserif they wish, otherwise administrative rights are required.markekraus commentedon Mar 1, 2018
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 CurrentUserin 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.bergmeister commentedon Mar 1, 2018
Wouldn't it be cleaner to have 2 dedicated cmdlets:
Install-ModuleForCurrentUserandInstall-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.markekraus commentedon Mar 1, 2018
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.
tommymaynard commentedon Mar 1, 2018
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.
bergmeister commentedon Mar 1, 2018
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)
markekraus commentedon Mar 1, 2018
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.bergmeister commentedon Mar 1, 2018
What if it used currentuser when not being elevated but only prompts to specify the type when being elevated?
20 remaining items
markekraus commentedon Mar 7, 2018
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.
rkeithhill commentedon Mar 11, 2018
Adding to Ryan Yates (@kilasuit) suggestion:
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.
SteveL-MSFT commentedon Mar 23, 2018
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
CurrentUseras 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-Scopebecause 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.
rkeithhill commentedon Mar 23, 2018
Totally agree.
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.
You don't have to wait 5-10 years from now. They've been frustrated ever since v5 shipped. :-)
kilasuit commentedon Jun 5, 2018
this was raised initially in #2 and really should have been fixed then
Jaykul commentedon Jul 11, 2018
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-Moduleto 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
edyoung commentedon Aug 23, 2018
See pull request #315 which implements the suggestion by Ryan Yates (@kilasuit) . FYI alerickson
bmanikm commentedon Sep 10, 2018
#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.
bmanikm commentedon Sep 13, 2018
Resolved with #315.
TomBonnerAtTFL commentedon Sep 13, 2018
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.
kilasuit commentedon Sep 13, 2018
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
edyoung commentedon Sep 13, 2018
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.
edyoung commentedon Nov 27, 2018
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.