0

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 (e.g. Get-Date, Test-Path, etc.).

Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118

1 Answers1

0

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.

deadlydog
  • 22,611
  • 14
  • 112
  • 118