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

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

问题描述

我在我创建的文件夹中有一个模块,C:\PowerShellScripts\Modules。我称这个mod.psm1。此文件包含两个简单的功能:Write-hello和Write-bye。



现在,我已将此路径(C:\PowerShellScripts\Modules)添加到我的PSModulePath环境变量路径。



因此,当我启动PowerShell时,这应该自动加载模块。正确?



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


write-hello:术语write-hello不被识别为
a cmdlet,函数,脚本文件或可操作程序的名称




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



我需要再次手动使用Import-Module。可能是错的?

解决方案

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


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

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

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

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

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

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

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

解决方案

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天全站免登陆