简体   繁体   中英

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.

If I do (Get-Item Env:\\PSModulePath).Value -Split ';' in a regular Windows PowerShell command prompt I get the following 7 paths:

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:

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

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

I'll open a new bug for StudioShell to get this fixed up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM