[英]PowerShell does not load all PSModulePaths when running from Visual Studio / Code
As you can see from my answer on my question here , for some reason when I run PowerShell from code in Visual Studio, either by calling powershell.Invoke , or by starting a new PowerShell process, it does not include all of the PSModulePaths that are included when I manually startup a Windows PowerShell command prompt. 从我对这里问题的回答中可以看出,由于某种原因,当我从Visual Studio中的代码运行PowerShell时,无论是通过调用powershell.Invoke还是通过启动新的PowerShell进程,它都不包括所有的PSModulePaths 。手动启动Windows PowerShell命令提示符时包含在内。
If I do (Get-Item Env:\\PSModulePath).Value -Split ';'
如果我这样做
(Get-Item Env:\\PSModulePath).Value -Split ';'
in a regular Windows PowerShell command prompt I get the following 7 paths: 在常规Windows PowerShell命令提示符下,我得到以下7条路径:
C:\Users\Dan Schroeder\Documents\WindowsPowerShell\Modules\
C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\
C:\Program Files\Microsoft Security Client\MpProvider\
C:\Program Files (x86)\\Code Owls LLC
However, if I run it from code I get the following 3 paths: 但是,如果我通过代码运行它,则会得到以下3条路径:
C:\Users\Dan Schroeder\Documents\WindowsPowerShell\Modules\
C:\Users\Dan Schroeder\Documents\WindowsPowershell\Modules
C:\Program Files (x86)\Code Owls LLC\StudioShell\bin\\..\\..
Why are these so different? 为什么这些是如此不同? Since when I run from code it doesn't include
C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\
, tons of the default built-in cmdlets are not available (eg Get-Date
, Test-Path
, etc.). 因为当我从代码运行时,它不包含
C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules\\
,所以大量的默认内置cmdlet不可用(例如, Get-Date
, Test-Path
等)。 )。
I found the cause of the problem, which was hidden in my question. 我找到了问题的原因,该问题已隐藏在我的问题中。 I uninstalled StudioShell (a Visual Studio PowerShell extension) and everything works correctly now.
我卸载了StudioShell (Visual Studio PowerShell扩展),现在一切正常。 It looks like there is a bug in that extension.
似乎该扩展程序中存在错误。
In my question you can see that it is the last PSModulePath listed when I ran from Visual Studio, and that it has a relative path, where the rest of them have an absolute path. 在我的问题中,您可以看到它是我从Visual Studio中运行时列出的最后一个PSModulePath,并且它具有相对路径,而其余路径具有绝对路径。
I'll open a new bug for StudioShell to get this fixed up. 我将为StudioShell打开一个新错误以修复此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.