Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell import-module doesn't find modules

I'm learning PowerShell and I'm trying to build my own module library.

I've written a simple module XMLHelpers.psm1 and put in my folder $home/WindowsPowerShell/Modules.

When I do:

 import-module full_path_to_XMLHelpers.psm1 

It works. But when I do:

import-module XMLHelpers 

It doesn't work and I get the error:

Import-Module : The specified module 'xmlhelpers' was not loaded because no valid module file was found in any module directory.

I've checked that the environment variable PSModulePath contains this folder. As it is a network folder, I've also tried to move it to a local folder and to modify PSModulePath but without success

 $env:PSModulePath=$env:PSModulePath+";"+'C:\local' 

Any idea on what could cause this issue?

like image 515
Serge Weinstock Avatar asked Jun 20 '11 14:06

Serge Weinstock


People also ask

How do I manually import a PowerShell Module?

Method 2—Install PowerShell Modules Manually To install PowerShell modules manually, you first need to determine your current PowerShell module directory path, download your new module to that path, and invoke the import-module command to let windows know it's there.

How do I automatically load PowerShell modules?

Module Auto-Loading Beginning in PowerShell 3.0, PowerShell imports modules automatically the first time that you run any command in an installed module. You can now use the commands in a module without any set-up or profile configuration, so there's no need to manage modules after you install them on your computer.

Where do I put PowerShell modules?

Installing Modules for all Users in Program Files If you want a module to be available to all user accounts on the computer, install the module in the Program Files location. The Program Files location is added to the value of the PSModulePath environment variable by default in Windows PowerShell 4.0 and later.


1 Answers

The module needs to be placed in a folder with the same name as the module. In your case:

$home/WindowsPowerShell/Modules/XMLHelpers/ 

The full path would be:

$home/WindowsPowerShell/Modules/XMLHelpers/XMLHelpers.psm1 

You would then be able to do:

import-module XMLHelpers 
like image 167
Rynant Avatar answered Sep 20 '22 22:09

Rynant