[英]How does PSModulePath environment property get composed?
This question is related to my other post - Using both desktop Powershell 5.1 and Powershell Core 6.1 这个问题与我的其他帖子有关 - 使用桌面Powershell 5.1和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. 基本上邪恶的根源是,当我打开桌面Powershell并检查
$env:PSModulePath
我看到PS.Core模块路径。
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
. 请注意
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: 我甚至没有
$PROFILE
脚本:
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. 可以看出,控制面板中没有提到PS.Core 6.1模块路径,但它可以在实际的PSModulePath环境变量中找到。
So, my question is - how is PSModulePath truly composed? 所以,我的问题是 - PSModulePath是如何组成的?
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). 我在Microsoft文档中找不到它(我的意思是我确实发现它是一个环境变量,但正如人们可以看到它还有更多)。 I must be missing something obvious.
我一定错过了一些明显的东西。
EDIT 1 编辑1
I opened Process Explorer and checked the environment of the parent process - explorer.exe. 我打开了Process Explorer并检查了父进程的环境 - explorer.exe。 Its PSModulePath is:
它的PSModulePath是:
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. 但是在杀死explorer.exe并再次运行它后,我可以看到PS.Core模块路径消失了。 And so reopening the Powershell shows proper module path.
因此,重新打开Powershell会显示正确的模块路径。
I suppose when I installed PS.Core 6.1 it modified the environment of the explorer.exe somehow. 我想当我安装PS.Core 6.1时,它以某种方式修改了explorer.exe的环境。 Or was it VS Code?
还是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. 我将不得不深入研究并向PS.Core或VS Code打开一个错误。
When PowerShell starts up it'll attempt to set the PSModulePath
env var by: 当PowerShell启动时,它将尝试通过以下方式设置
PSModulePath
env var :
%PSModulePath%
from the host process %PSModulePath%
的现有值 %windir%\\system32
module folder as well %windir%\\system32
模块文件夹 $env:PSModulePath
by combining all three $env:PSModulePath
的值 If 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 如果你在那里看到一个意外的值,
pwsh.exe
可能只是从父进程继承它,它包含在步骤1中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.