Powershell 导入模块找不到模块 [英] Powershell import-module doesn't find modules

查看:44
本文介绍了Powershell 导入模块找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 PowerShell,并且正在尝试构建自己的模块库.

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

我编写了一个简单的模块 XMLHelpers.psm1 并将其放在我的文件夹 $home/WindowsPowerShell/Modules 中.

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

当我这样做时:

 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 : 指定的模块 'xmlhelpers' 未加载,因为在任何模块目录中都找不到有效的模块文件.

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

我已检查环境变量 PSModulePath 是否包含此文件夹.由于它是网络文件夹,我也尝试将其移动到本地文件夹并修改 PSModulePath 但没有成功

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?

推荐答案

模块需要放在与模块同名的文件夹中.在你的情况下:

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

$home/WindowsPowerShell/Modules/XMLHelpers/

完整路径为:

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

然后你就可以:

import-module XMLHelpers

这篇关于Powershell 导入模块找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆