question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows PowerShell inherits PSModulePath from PowerShell Core

See original GitHub issue

If you start Windows PowerShell from PowerShell Core, you get the $env:PSModulePath from PowerShell Core.

In my opinion, this should be a 6.0.0 blocker. Also, if any work needs to be done in Windows PowerShell to fix this, we should do it ASAP.

Steps to reproduce

From PowerShell Core:

Start-Process powershell

This will open a new instance of Windows PowerShell. From this instance:

$env:PSModulePath

Expected behavior

C:\Users\jaiello\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

Also, PSReadline should load.

Actual behavior

C:\Users\jaiello\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\6.0.0.12\Modules

Also, PSReadline doesn’t load because it can’t be found.

Environment data

For PowerShell Core:

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
GitCommitId                    v6.0.0-alpha.12
CLRVersion
BuildVersion                   3.0.0.0
PSRemotingProtocolVersion      2.3
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

For Windows PowerShell;

Name                           Value
----                           -----
PSVersion                      5.1.14931.1000
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14931.1000
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
SteveL-MSFTcommented, Mar 9, 2017

Agree with @iSazonov this is by-design as child processes are expected to inherit environment from parent. The way to address this may be to have PSModulePath in https://github.com/PowerShell/PowerShell-RFC/blob/master/1-Draft/RFC0015-PowerShell-StartupConfig.md

2reactions
iSazonovcommented, Mar 9, 2017

It is expected because subprocess always inherits environment variables of parent process. If we change the default behavior it can confuse users. We would backup PSModulePath on startup and restore before create subprocess. Or create $env:PSModulePath_Backup and check it on PowerShell startup. The second is seems easier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about PSModulePath - PowerShell
The PSModulePath environment variable contains a list of folder locations that are searched to find modules and resources.
Read more >
PowerShell Core doesn't inherit PSModulePath ...
Windows PowerShell correctly inherits environment variables from the environment -- although it may add paths to these variables, it doesn't ...
Read more >
How does PSModulePath environment property get ...
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....
Read more >
Inheritance in PowerShell Classes - SAPIEN Information Center
PowerShell classes can inherit from only one base class, so you can't specify more than one class name. (The class can implement multiple ......
Read more >
Set PSModulePath Environment Variable with PowerShell ...
PowerShell - Get OS Environmental Variables without Expanding. You can use the Get-Item cmdlet with the -path parameter and then pass that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found