Powershell import-module doesn't find modules

Viewed 283599

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?

8 Answers

I had this problem, but only in Visual Studio Code, not in ISE. Turns out I was using an x86 session in VSCode. I displayed the PowerShell Session Menu and switched to the x64 session, and all the modules began working without full paths. I am using Version 1.17.2, architecture x64 of VSCode. My modules were stored in the C:\Windows\System32\WindowsPowerShell\v1.0\Modules directory.

try with below on powershell:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted
import-module [\path\]XMLHelpers.psm1

Instead of [] put the full path

Full explanation of this and that

Related