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