Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell v2.0 Modules: Default Load Path (User / Windows system folder)?

This is with respect to this question which I had asked earlier - Powershell: Installing Modules on Target System

  • What is the default module load path ? Now after so many days, it has started giving this error (from my C# code)

    Cannot find path 'C:\Users\angshuman\Documents\WindowsPowerShell\Modules\MyPSModules\MyPsModules.‌​psd1' because it does not exist.

    All the while it was nicely loading from the SysWow64 folder path
  • Why it is suddenly searching in user folder rather than Windows folder?

I am executing the same code via C# on a Windows 7 64-bit OS

    _ps = PowerShell.Create();   
    _ps.AddScript("Import-Module MyPSModules -PassThru");
    Collection<PSObject> psObjects = _ps.Invoke();
like image 293
Angshuman Agarwal Avatar asked Sep 17 '12 10:09

Angshuman Agarwal


People also ask

What is the default path for PowerShell modules?

By default, on Windows 10 and higher, that location is $HOME\Documents\PowerShell\Modules . On Linux or Mac, the CurrentUser location is $HOME/. local/share/powershell/Modules .

Where is the PowerShell module path?

On Windows, the user-specific location is the PowerShell\Modules folder located in the Documents folder in your user profile. The specific path of that location varies by version of Windows and whether or not you are using folder redirection. Microsoft OneDrive can also change the location of your Documents folder.

How do I install all PowerShell modules?

Installing PowerShell modules from the PowerShell Gallery is the easiest way to install modules. To install a package or module from the Gallery, we use the command: Install-Module or Install-Script cmdlet, depending on the package type.


2 Answers

And if you want to have them to have a better readability you can use this:

$env:PSModulePath.split(';')

enter image description here

like image 129
Jose Ortega Avatar answered Dec 06 '22 06:12

Jose Ortega


$env:psmodulePath is the automatic variable which holds the path used to discover modules. If it's not set, PowerShell looks in c:\windows\system32\WindowsPowerShell\v1.0\modules and MyDocuments\WindowsPowerShell\modules.

So it should by default always be looking in both places.

I haven't done much 32-on-64 coding, but I could see it using SysWow64 (instead of System32) if you were running a 32-bit app on a 64-bit OS.

like image 37
Mike Shepard Avatar answered Dec 06 '22 07:12

Mike Shepard