PowerShell 模块(尤其是 PSReadline)如何在 V5 中自动加载?

How are PowerShell Modules (particularly PSReadline) loaded automatically in V5?

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

我已经完成了所有 :

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

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

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