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/
My finding with PS 5.0 on Windows 7: $ENV:PsModulePath
has to end with a . This normally means it will load all modules in that path.
I'm not able to add a single module to $env:PsModulePath and get it to load with Import-Module ExampleModule
. I have to use the full path to the module. e.g. C:\MyModules\ExampleModule
. I am sure it used to work.
For example: Say I have the modules:
C:\MyModules\ExampleModule
C:\MyModules\FishingModule
I need to add C:\MyModules\
to $env:PsModulePath
, which will allow me to do
Import-Module ExampleModule
Import-Module FishingModule
If for some reason, I didn't want FishingModule
, I thought I could add C:\MyModules\ExampleModule
only (no trailing \), but this doesn't seem to work now. To load it, I have to Import-Module C:\MyModules\ExampleModule
Interestingly, in both cases, doing Get-Module -ListAvailable
, shows the modules, but it won't import. Although, the module's cmdlets seem to work anyway.
AFAIK, to get the automatic import to work, one has to add the name of the function to FunctionsToExport in the manifest (.psd1) file. Adding FunctionsToExport = '*'
, breaks the auto load. You can still have Export-ModuleMember -Function *
in the module file (.psm1).
These are my findings. Whether there's been a change or my computer is broken, remains to be seen. HTH
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
1.This will search XMLHelpers/XMLHelpers.psm1 in current folder
Import-Module (Resolve-Path('XMLHelpers'))
2.This will search XMLHelpers.psm1 in current folder
Import-Module (Resolve-Path('XMLHelpers.psm1'))
Some plugins require one to run as an Administrator
and will not load unless one has those credentials active in the shell.
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.
I think that the Import-Module
is trying to find the module in the default directory C:\Windows\System32\WindowsPowerShell\v1.0\Modules
.
Try to put the full path, or copy it to C:\Windows\System32\WindowsPowerShell\v1.0\Modules