This question is related to my other post - Using both desktop Powershell 5.1 and Powershell Core 6.1
Basically the root of the evil is that when I open a desktop Powershell and check $env:PSModulePath I see PS.Core module path there.
Please, observe:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\me> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.503
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.503
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\Users\me> $env:PSModulePath -split ';'
C:\Users\me\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\me>
Notice c:\program files\powershell\6\Modules.
Now when I inspect the Environment variables in the Control Panel I see a different picture:
User

System

I do not even have the $PROFILE script:
PS C:\Users\me> Test-Path $PROFILE
False
PS C:\Users\me>
As one can see PS.Core 6.1 module path is not mentioned in the Control Panel, yet it is found in the actual PSModulePath environment variable.
So, my question is - how is PSModulePath truly composed?
I could not find it in the Microsoft documentation (I mean I did find it is an environment variable, but as one can see there is more to it). I must be missing something obvious.
EDIT 1
I opened Process Explorer and checked the environment of the parent process - explorer.exe. Its PSModulePath is:
C:\Users\mkharitonov\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
But after killing the explorer.exe and running it again, I can see the PS.Core module path disappeared. And so reopening the Powershell shows proper module path.
I suppose when I installed PS.Core 6.1 it modified the environment of the explorer.exe somehow. Or was it VS Code? Anyway, restarting the explorer fixes the issue.
I will have to dig into it and open a bug either to PS.Core or VS Code.
When PowerShell starts up it'll attempt to set the PSModulePath env var by:
%PSModulePath% from the host process%windir%\system32 module folder as well$env:PSModulePath by combining all threeIf you see an unexpected value in there, pwsh.exe might have simply inherited it frmo the parent process and it's included in step 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With