2

我最近安装了 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

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

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

4

2 回答 2

4

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

于 2016-11-29T16:17:43.033 回答
1

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

于 2016-11-29T10:37:34.963 回答