Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell PSModulePath环境属性是如何组合的?_Powershell - Fatal编程技术网

Powershell PSModulePath环境属性是如何组合的?

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 ----

这个问题与我的另一个帖子有关-

基本上,问题的根源在于,当我打开桌面Powershell并选中
$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%
    的现有值
  • 从主机应用程序的配置中读取当前用户和所有用户的默认模块路径
  • 如果在Windows上,请同时读取
    %windir%\system32
    模块文件夹
  • 通过组合所有三个参数更新
    $env:PSModulePath
    的值

  • 如果您在其中看到一个意外值,
    pwsh.exe
    可能只是从父进程继承了它,并且它包含在步骤1

    :-D中,尽管看起来它仍然应该继承进程级别的env var,weird@MathiasR.Jessen-你的观察让我找到了解决办法。见编辑1。请将您的评论安排为答案,以便我可以信任您。更正-我的问题是
    powershell.exe
    ,而不是
    pwsh.exe
    。但我猜如果他们以某种方式修改父资源管理器进程的环境,他们就会互相搞砸。