Skip to content

Windows installer breaks PSModulePath #524

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

Open
justinian opened this issue May 8, 2017 · 17 comments
Open

Windows installer breaks PSModulePath #524

justinian opened this issue May 8, 2017 · 17 comments

Comments

@justinian
Copy link

I have a number of user-scope modules installed in ~/Documents/WindowsPowerShell/Modules, which is in the PSModulePath by default. After installing via the windows installer, under user variables, my PSModulePath was set to ;C:\Users\justin\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell (note the leading ;, which looks like a failed attempt to append to the existing path), which caused the default path to not be searched, and my modules to all fail to import. This was a simple fix once I had figured out what was going on, but it took some time to discover.

@quoctruong
Copy link
Contributor

@justinian, thanks for reporting the bug. Do you mean that the installer remove ~/Documents/WindowsPowerShell/Modules from the path too?

@justinian
Copy link
Author

justinian commented May 8, 2017

I'm actually not sure of the original value, it might have been empty, or it may have contained the default value. According to this MSDN article:

When Windows PowerShell starts, PSModulePath is created as a system environment variable with the
following default value: $home\Documents\WindowsPowerShell\Modules; $pshome\Modules.

I'm not sure if that means the permanent settings are updated the first time PowerShell runs, or if this is the default if PowerShell is started without a PSModulePath set. I have not explicitly set the variable myself.

However, I do see that the system-wide setting is correct, and had the SDK path properly appended:

%ProgramFiles(x86)%\WindowsPowerShell\Modules;%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell

@quoctruong
Copy link
Contributor

@justinian, that's interesting. I wasn't able to repro this on my machine by installing the SDK for a specific user. Can I ask do you have this problem when you install it system-wide?

@justinian
Copy link
Author

(Sorry for the late reply!) I believe I installed it system-wide previously since both the user and system paths were modified. Testing on another machine system-wide, I see that it only touched my system-wide PSModulePath and it looks correct, so ¯\_(ツ)_/¯

@figaw
Copy link

figaw commented Sep 6, 2018

I have also experienced that it overwrites the PSModulePath environment variable. This is highly annoying.

@dprothero
Copy link

Same thing happened to me today.

@quoctruong
Copy link
Contributor

It seems like the issue happens if the PSModulePath for User is empty initially. We are fixing this in the next cloud SDK release.

@quoctruong quoctruong reopened this Sep 11, 2019
@deisner
Copy link

deisner commented Nov 26, 2019

@quoctruong I'm glad this will be fixed -- this caused a problem for me with the latest PowerShell 7 preview (and probably in the final release): PowerShell/PowerShell#11172

@quoctruong
Copy link
Contributor

@deisner This should already be fixed with the latest version of the Google Cloud SDK.

@deisner
Copy link

deisner commented Nov 27, 2019

@quoctruong I start out with a PSModulePath environment variable set in the machine scope, but not set at all in the user scope. At this point, from a cmd.exe shell:

C:\Users\david>set psmodulepath
PSModulePath=C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer;C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\

I then run the latest GoogleCloudSDKInstaller.exe, checking the options to install Cloud Tools for PowerShell, and to run gcloud init. After installation, PSModulePath is set in the user scope, to this:

C:\Users\david>set psmodulepath
PSModulePath=C:\Users\david\Documents\WindowsPowerShell\Modules;C:\Users\david\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell

Is this the intended behavior? This is on Windows 10 Enterprise 1909, by the way.

@quoctruong
Copy link
Contributor

What is the version of your Google Cloud SDK?

@deisner
Copy link

deisner commented Nov 27, 2019

C:\Users\david\AppData\Local\Google\Cloud SDK>gcloud version
Google Cloud SDK 272.0.0
bq 2.0.50
core 2019.11.16
gsutil 4.46

I should add that the new behavior of PowerShell 7 preview.6 might be under review -- arguably the user and machine PSModulePath environment variables should be concatenated (or kept concatenated) by PowerShell, which was the previous behavior. See PowerShell/PowerShell#11172 (comment).

@quoctruong
Copy link
Contributor

I see. So you are using PowerShell 7 in this case? Is it possible to test it under PowerShell 6?

@deisner
Copy link

deisner commented Dec 2, 2019

I am using PowerShell 7-preview.6. There was no problem with PowerShell 7-preview.5 or earlier. I just installed PowerShell 6.22, and my PSModulePath looks like this:

PS C:\Users\david> $env:PSModulePath -split ';'
C:\Users\david\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

... while in PowerShell 7.0.0-preview.6 it looks like this:

PS C:\Users\david> $env:PSModulePath -split ';'
C:\Users\david\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7-preview\Modules
C:\Users\david\Documents\WindowsPowerShell\Modules
C:\Users\david\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell

... and (after uninstalling PS7-preview.6 and re-installing PS7-preview.5), in Powershell 7.0.0-preview.5 it looks like this:

PS C:\Users\david> $env:PSModulePath -split ';'
C:\Users\david\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7-preview\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

And, for completeness, here's PowerShell 5.1:

PS C:\Users\david> $env:PSModulePath -split ';'
C:\Users\david\Documents\WindowsPowerShell\Modules
C:\Users\david\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\

My User PSModulePath environment variable:

%HomeDrive%%HomePath%\Documents\WindowsPowerShell\Modules
C:\Users\david\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\PowerShell

and finally, my System PSModulePath is

%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvPkgConverter
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\Sequencer\AppvSequencer
C:\Program Files (x86)\Windows Kits\10\Microsoft Application Virtualization\

@quoctruong
Copy link
Contributor

@deisner So what did the Cloud SDK installation do to your PSModulePath?

@deisner
Copy link

deisner commented Dec 5, 2019

Just to save time: regarding my previous comment

I should add that the new behavior of PowerShell 7 preview.6 might be under review

It looks like this is indeed a problem with PS7-preview.6, and that the behavior will be fixed: PowerShell/PowerShell#11172 (comment)

In short, I don't think it's not a Cloud SDK issue.

@Tayaah
Copy link

Tayaah commented Dec 2, 2020

I got this problem (my PSModulePath is broken) and actually, I need to use SDK and some modules that are getting fail to import.
Sorry, but I'm a little bit beginner with this, so how I can fix that? To continue to use SDK and my modules.
I mean, how can I get back the PSModulePath working again?

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

No branches or pull requests

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy