Powershell PSModulePath环境属性是如何组合的?
这个问题与我的另一个帖子有关- 基本上,问题的根源在于,当我打开桌面Powershell并选中Powershell PSModulePath环境属性是如何组合的?,powershell,Powershell,这个问题与我的另一个帖子有关- 基本上,问题的根源在于,当我打开桌面Powershell并选中$env:PSModulePath时,我在那里看到了PS.Core模块路径 请注意: Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\Users\me> $PSVersionTable Name Value ----
$env:PSModulePath
时,我在那里看到了PS.Core模块路径
请注意:
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>
注意c:\ProgramFiles\powershell\6\Modules
现在,当我检查控制面板中的环境变量时,我看到了不同的图片:
用户
系统
我甚至没有$PROFILE
脚本:
PS C:\Users\me> Test-Path $PROFILE
False
PS C:\Users\me>
可以看到,PS.Core 6.1模块路径未在控制面板中提及,但在实际的PSModulePath环境变量中可以找到
所以,我的问题是——PSModulePath是如何真正组成的
我在Microsoft文档中找不到它(我的意思是我确实发现它是一个环境变量,但正如人们所看到的,它还有更多)。我一定错过了什么明显的东西
编辑1
我打开了Process Explorer并检查了父进程的环境-Explorer.exe。其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
但是在杀死explorer.exe并再次运行它之后,我可以看到PS.Core模块路径消失了。因此,重新打开Powershell会显示正确的模块路径
我想当我安装PS.Core 6.1时,它以某种方式修改了explorer.exe的环境。或者它是VS代码?无论如何,重新启动资源管理器可以解决此问题
我将不得不深入研究它,并打开一个错误,无论是PS.Core还是VS代码。当PowerShell启动时,它将尝试通过以下方式:
%PSModulePath%
的现有值%windir%\system32
模块文件夹$env:PSModulePath
的值如果您在其中看到一个意外值,
pwsh.exe
可能只是从父进程继承了它,并且它包含在步骤1:-D中,尽管看起来它仍然应该继承进程级别的env var,weird@MathiasR.Jessen-你的观察让我找到了解决办法。见编辑1。请将您的评论安排为答案,以便我可以信任您。更正-我的问题是powershell.exe
,而不是pwsh.exe
。但我猜如果他们以某种方式修改父资源管理器进程的环境,他们就会互相搞砸。