即使在环境变量中定义了模块路径后,Powershell 模块也不会加载 [英] Powershell Module not loading even after the module path is defined in environment variables

查看:25
本文介绍了即使在环境变量中定义了模块路径后,Powershell 模块也不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建的文件夹 C:PowerShellScriptsModules 中有一个模块.我称之为 mod.psm1.该文件包含两个简单的函数:Write-hello 和 Write-bye.

I have a module in a folder that I have created, C:PowerShellScriptsModules. I call this mod.psm1. This file contains two simple functions: Write-hello and Write-bye.

现在,我已将此路径(C:PowerShellScriptsModules)添加到我的 PSModulePath 环境变量路径中.

Now, I have added this path(C:PowerShellScriptsModules) to my PSModulePath Environment variables path.

因此,当我启动 PowerShell 时,这应该会自动加载模块.对吗?

Accordingly, this should auto load the module when I start PowerShell. Correct?

但是当我运行 PowerShell 并尝试 Write-hello 或 Write-bye 时,它​​会报错

But when I run PowerShell and try Write-hello or Write-bye it gives an error

write-hello : 术语write-hello"未被识别为cmdlet、函数、脚本文件或可运行的程序

write-hello : The term 'write-hello' is not recognized as the name of a cmdlet, function, script file, or operable program

即使 $ENV:PSModulePath 显示我的路径 (C:PowerShellScriptsModules),PowerShell 也不会加载 mod.psm1 文件

PowerShell does not load the mod.psm1 file even though $ENV:PSModulePath shows my path (C:PowerShellScriptsModules)

我需要再次手动使用 Import-Module.有什么问题?

And I need to manually use Import-Module again. What could be wrong?

推荐答案

我想通了.我需要将我的 mod.psm1 文件添加到名为mod"的文件夹中.现在我可以在启动 PowerShell 时直接访问我的 cmdlet write-hello 或 write-bye.

I figured it out. I needed to add my mod.psm1 file to a folder named "mod". Now I can directly access my cmdlets write-hello or write-bye when i start PowerShell.

这篇关于即使在环境变量中定义了模块路径后,Powershell 模块也不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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