Open justinian opened 7 years ago
@justinian, thanks for reporting the bug. Do you mean that the installer remove ~/Documents/WindowsPowerShell/Modules from the path too?
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
@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?
(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 ¯\_(ツ)_/¯
I have also experienced that it overwrites the PSModulePath environment variable. This is highly annoying.
Same thing happened to me today.
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 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
@deisner This should already be fixed with the latest version of the Google Cloud SDK.
@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.
What is the version of your Google Cloud SDK?
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 https://github.com/PowerShell/PowerShell/issues/11172#issuecomment-558883569.
I see. So you are using PowerShell 7 in this case? Is it possible to test it under PowerShell 6?
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\
@deisner So what did the Cloud SDK installation do to your PSModulePath?
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: https://github.com/PowerShell/PowerShell/issues/11172#issuecomment-561887323
In short, I don't think it's not a Cloud SDK issue.
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?
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.