I can鈥檛 seem to think of valid use case for the reported steps (running Windows PowerShell from PowerShell Core console). However, it鈥檚 something unexpected so bringing it to your attention.
Environment: PowerShell Core 6 (GA) on Windows
In the pwsh:
powershellThe psmodulepath should be the value from Windows PowerShell.
The value is from the pwsh session.
I can not repo.
If you first run Windows PowerShell do you see $env:psmodulepath?
I can repro this. PS Core has a separate PSModulePath environment variable because of the separation from Windows PowerShell modules. unfortunately, when you start Windows PowerShell from PowerShell Core, Windows PowerShell sees the PSModulePath environment path and adopts it. If you do this the other way around and start PowerShell Core from Windows PowerShell, PowerShell core ignores the PSModulePath environment variable and uses its own.
In PowerShell Core:
$env:PSModulePath; powershell -c '$env:PSModulePath'
C:\Users\username\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6.0.0-rc.2\Modules
C:\Users\username\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6.0.0-rc.2\Modules
In Windows PowerShell:
$env:PSModulePath; pwsh -c '$env:PSModulePath'
C:\Users\username\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files\Intel\;C:\opscode\chefdk\modules\
C:\Users\username\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6.0.0-rc.2\Modules
Yes, I semms mixed the directions.
It is dup #2636
Thank you guys. I checked the discussion in #2636. I see the behavior is caused from the subprocess inherits the variable from its parent now. Wondering why it's does not behave the same the other way around though (launching PowerShell Core from Windows PowerShell)? Launching Windows PowerShell from PowerShell Core may be a less common use case. However, it definitely cause inconsistent user experience.
@LawrenceHwang Because PowerShell Core needs to ignore the Windows PowerShell PSModulePath. PSModulePath is set on your system and passed to Windows PowerShell when it starts you can see this by starting cmd.exe form start and running echo %PSModulePath%. PowerShell Core needs to ignore this by default to prevent Windows Powershell Modules from loading by default and to find the PowerShell Core modules.
This is ridiculous.
If you're not actually reading the variable from the environment that's not really an environment variable, is it?