-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
This may be by design, but I wanted to make sure as it can lead to some unpredictable results when calling Windows PowerShell from PowerShell Core.
When calling powershell.exe (to run some command which is not available in PowerShell Core, such as Show-Command) - the PSModulePath environment variable seems to be inherited from pwsh.exe.
One example is calling Show-Command against a command which exists only in a PowerShell Core module (e.g. New-AzVm from C:\Program Files\PowerShell\Modules\Az.Compute):
powershell.exe -noprofile 'Show-Command New-AzVm'
This should not have worked since Az.Compute is only installed in PowerShell Core, and not available in any of the PSModule paths for Windows PowerShell (on my machine).
This is a trivial example, but could have lead to more unpredictable results if a PowerShell Core-only module was called in a Windows PowerShell runspace.
Steps to reproduce
# From pwsh.exe on Windows
powershell.exe -noprofile '$env:psmodulepath'Expected behavior
C:\Users\janring\Documents\WindowsPowerShell;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
Actual behavior
C:\Users\janring\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
Environment data
Name Value
---- -----
PSVersion 6.1.2
PSEdition Core
GitCommitId 6.1.2
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0