我正在尝试加载执行自定义 cmdlet 函数的 PowerShell 模块,但我无法加载它...我已应用 several 的解决方案previous questions ,但现在我只是在兜圈子。以下是我到目前为止所做的规范以及返回的特定错误。请注意,由于我是 PowerShell 和一般编程的新手,所以我的问题不是文件路径问题而是我的实际函数中的逻辑错误并不会让我感到惊讶:
从两个不同的路径打开项目文件:
function push-project( $project )
{
pushd ~/Documents/Visual Studio 2015/Projects/$project;
pushd ~/Documents/GitHub/$project;
}
New-Alias -Name pp -Value push-project;
ProfileFunctions.psm1
创建了一个模块在以下目录中:
~\Documents\WindowsPowerShell\Modules\ProfileFunctions\ProfileFunctions.psm1
pp $projectName
进入 PS 控制台窗口,但返回的错误是标准无法识别的:pp : The term 'pp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
pp MyFirstApp
~~
CategoryInfo : ObjectNotFound: (pp:String) [], CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
最佳答案
我将您的代码复制并粘贴到我这里的 Windows 8.1 机器中。它工作得很好(除了文件夹名称不存在,因为我没有 Visual Studio)。
我想到的可能会阻止您的模块工作的事情:
该文件实际上称为 ProfileFunctions.psm1.ps1
或 ProfileFunctions.psm1.txt
或者其他的东西。
Modules 文件夹保存在其他人的文档文件夹或公共(public)文档文件夹中。
您不小心在文件夹名称中添加了一个空格(它必须是 WindowsPowerShell
,而不是 Windows PowerShell
)。
关于Powershell模块未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31898150/