这个问题与我的另一篇文章有关 -同时使用桌面 Powershell 5.1 和 Powershell Core 6.1 https://stackoverflow.com/questions/56875328/using-both-desktop-powershell-5-1-and-powershell-core-6-1
基本上邪恶的根源是当我打开桌面 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>
Notice c:\program files\powershell\6\Modules
.
现在,当我检查控制面板中的环境变量时,我看到了不同的图片:
User
System
我什至没有$PROFILE
script:
PS C:\Users\me> Test-Path $PROFILE
False
PS C:\Users\me>
可以看到,控制面板中没有提及 PS.Core 6.1 模块路径,但在实际的 PSModulePath 环境变量中可以找到它。
所以,我的问题是 - PSModulePath 真正是如何组成的?
我在 Microsoft 文档中找不到它(我的意思是我确实发现它是一个环境变量,但正如人们所看到的,还有更多内容)。我一定错过了一些明显的东西。
EDIT 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 Code?无论如何,重新启动资源管理器可以解决问题。
我将不得不深入研究它并向 PS.Core 或 VS Code 打开一个错误。