Skip to content
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

Installing chocolatey removes $env:PSModulePath changes for current powershell session #295

Closed
chrissimon-au opened this issue May 30, 2015 · 7 comments
Assignees
Milestone

Comments

@chrissimon-au
Copy link

When installing in a powershell process with something like:

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

After the install, $env:PSModulePath has reverted to the Machine level environment variable.

This is causing problems for me as the Machine level variable only has:

 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\AWS Tools\PowerShell\

But as part of establishing a powershell session, $env:PSModulePath looks like:

C:\Users\Administrator\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\AWS Tools\PowerShell\

After installing chocolatey, it reverts to:

 C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\AWS Tools\PowerShell\

And the absence of the Documents and Program Files paths causes problems for other things I'm trying to do in the same script.

Seems likely this is being done by Update-SessionEnvironment. The need for Update-SessionEnvironment is clear, but could it possible merge with the existing $env:PSModulePath rather than assuming that the process has not yet modified it?

@ferventcoder
Copy link
Member

To be clear this is only during the install.

Where are the other values resolved from?

@chrissimon-au
Copy link
Author

Yes, I've only noticed this during install.

Not sure where those other values are coming from. https://msdn.microsoft.com/en-us/library/dd878326%28v=vs.85%29.aspx suggests the Documents path is a default ($home\Documents\WindowsPowerShell\Modules) - perhaps it's being added by Powershell itself - but doesn't explain the Program Files path. I'm still hunting that down - will let you know if/when I find it.

But either way - shouldn't in-process changes to $env:PSModulePath be respected, wherever they've come from? If they were set by the script that's installing chocolatey, then you wouldn't be able to resolve them from anywhere other than $env:PSModulePath.

@ferventcoder
Copy link
Member

The problem is that Update-Session is somewhat naive, it only loads the values from the registry.

@ferventcoder
Copy link
Member

By the way, this is a duplicate of #129 - let's continue discussion there.

This is not a duplicate, it's only related.

@ferventcoder
Copy link
Member

To be clear it's only messing up changes in the current powershell session. Once you close and reopen powershell, everything is back to normal.

@ferventcoder ferventcoder changed the title Installing chocolatey from powershell trashes $env:PSModulePath changes Installing chocolatey removes $env:PSModulePath changes for current powershell session Jun 30, 2015
@ferventcoder ferventcoder added this to the 0.9.10.x milestone Jun 30, 2015
@ferventcoder ferventcoder modified the milestones: 0.9.10, 0.9.10.x Mar 20, 2016
@ferventcoder ferventcoder self-assigned this Mar 20, 2016
ferventcoder added a commit that referenced this issue Mar 20, 2016
When running Chocolatey install / refreshenv, Chocolatey should not
replace PSModulePath. It should keep the current value.
ferventcoder added a commit that referenced this issue Mar 20, 2016
* stable:
  (GH-412)(GH-664) PoSh tab completion / refreshenv
  (GH-295) Do not replace PSModulePath
  (GH-664) RefreshEnv Should also work in PowerShell
  (GH-412) update parameter name for skip scripts
  (GH-663) Search just by id
  (doc) update how to pass args
@eavonius
Copy link

eavonius commented Jun 4, 2016

Hey guys just throwing a comment in here since I've been following this related to #129. Wouldn't it make sense that if any packages you install make persistent changes to the system or user PSMODULEPATH, at the conclusion of those packages, running refreshenv should cause PSMODULEPATH to be whatever is in the user variable (from the registry) and if a user level variable is not defined, it would be whatever is the system variable in the registry? This is what the command prompt normally does from testing I've done.

Curious what others think. Have run some of this by rob but I don't want to suggest he make a change that conflicts with what the rest of the community would expect. Thanks!

@ferventcoder
Copy link
Member

@eavonius Stay tuned, I just put some c# code into Chocolatey that may correct #129 for you. See #439 and the commits associated with that.

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

No branches or pull requests

4 participants