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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With