代码之家  ›  专栏  ›  技术社区  ›  leeand00

我的powershell配置文件中的函数不显示?

  •  0
  • leeand00  · 技术社区  · 6 年前

    ExecutionPolicy 因为机器设置为 AllSigned .

    PS> Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
    

    目前我的简介中没有太多内容,但随着新任务的出现,我希望能够像这样向其中添加函数:

    ## Auth stuff
    #Import-Module $env:USERPROFILE\Documents\WindowsPowerShell\storecredz.psm1
    
    # NOTE: This sets the ExecutionPolicy to Bypass for the current powershell window...
    #       `Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process`
    
    
        function initAssets($blah) {
    
            $Host.UI.RawUI.WindowTitle = "Assets - New Beta"
            Import-Module $env:USERPROFILE\Documents\WindowsPowerShell\psm\assets\init.psm1
        }
    

    上面是我的powershell配置文件中的内容…并且在设置 对于PS窗口,我运行 .\Microsoft.PowerShell_profile.ps1 我以为它会把我的 initAssets 功能…但不是。

    当我按tab键来完成功能时,它可能不会向上拉这个键,有什么特别的原因吗?配置文件运行时没有错误…我在新的Powershell窗口中尝试过它。

    0 回复  |  直到 6 年前
        1
  •  1
  •   JosefZ    6 年前

    应用 Dot sourcing operator .

    在当前作用域中运行脚本,以便任何函数、别名和

    使用如下:

    . .\Microsoft.PowerShell_profile.ps1
    

    另一个提示:将默认执行策略设置为 RemoteSigned 而不是 AllSigned .