【问题标题】:How are PowerShell Modules (particularly PSReadline) loaded automatically in V5?V5 中如何自动加载 PowerShell 模块(尤其是 PSReadline)?
【发布时间】:2016-11-30 03:44:52
【问题描述】:

我最近安装了 Windows 10,其中包括 PowerShell V5,确切地说是5.1.14393.206 ($PSVersionTable.PSVersion)。

在新计算机上我安装PSReadline。但是,Windows 10 已经安装了它。

我的问题是,当没有配置文件可以导入时,PSReadline 是如何自动加载的(或从中调用命令)?

作为证据,我运行了这段代码:

$PROFILE | Get-Member -MemberType NoteProperty | % {
    $path = $PROFILE.$($_.Name);
    $exists = Test-Path $path;
    [pscustomobject]@{ Path = $path; Exists = $exists }
}

要得到这个:

Path                                                                        Exists
----                                                                        ------
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1                       False
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1  False
C:\Users\tahir\Documents\WindowsPowerShell\profile.ps1                       False
C:\Users\tahir\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1  False

https://stackoverflow.com/a/23942543/288393:

  • 没有调用 PSReadline 的 Import-Module,因为没有配置文件可以调用它。
  • 没有在 PSReadline 模块中发出命令,因为和以前一样,没有配置文件可以调用它。

有人可以解释这种行为吗?

【问题讨论】:

标签: powershell windows-10 powershell-5.0 psreadline


【解决方案1】:

如果进程是交互式的,控制台主机中有特殊代码可以加载 PSReadline。可以看代码here

【讨论】:

  • (我承认这与 PetSerAl 的答案相同。)
【解决方案2】:

PSReadline 位于预定义的模块文件夹C:\Program Files\WindowsPowerShell\Modules 中,因为它位于此处 PowerShell 的自动 cmdlet 发现和模块加载过程将在调用其中的任何函数时选择并加载模块。那个过程added in PS v3

【讨论】:

  • 虽然您所说的自动 cmdlet 发现是正确的,但这并不是自动加载 PSReadline 的方式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多