Powershell模块未加载

标签 powershell module

我正在尝试加载执行自定义 cmdlet 函数的 PowerShell 模块,但我无法加载它...我已应用 several 的解决方案previous questions ,但现在我只是在兜圈子。以下是我到目前为止所做的规范以及返回的特定错误。请注意,由于我是 PowerShell 和一般编程的新手,所以我的问题不是文件路径问题而是我的实际函数中的逻辑错误并不会让我感到惊讶:

  • 我为自定义 cmdlet 创建了一个配置文件函数,它允许我
    从两个不同的路径打开项目文件:
           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.ps1ProfileFunctions.psm1.txt或者其他的东西。

    Modules 文件夹保存在其他人的文档文件夹或公共(public)文档文件夹中。

    您不小心在文件夹名称中添加了一个空格(它必须是 WindowsPowerShell ,而不是 Windows PowerShell )。

    关于Powershell模块未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31898150/

    相关文章:

    powershell - 使用参数不在脚本文件中的Powershell

    powershell - 如何在 Write-Host 中使用十六进制颜色代码?

    javascript - 从依赖项中的 node_modules 复制文件

    php - Symfony 1.4 动态模板

    mysql - 如何从类中调用模块?

    powershell - 在 Azure 订阅之间移动 V2 (ARM) 虚拟机

    postgresql - 连接到 docker postgres 实例 : "The server encountered an internal error and was unable to complete your request." 时出现 pgadmin 错误

    powershell - 如何从另一个 Powershell 过滤器调用 Powershell 过滤器?

    vue.js - Vue 找不到模块图片位置

    Julia 中的模块别名