3

I recently installed Windows 10, which includes V5 of PowerShell, or 5.1.14393.206 to be exact ($PSVersionTable.PSVersion).

On new computers I install PSReadline. However, Windows 10 comes with it already installed.

My question is, how is PSReadline loading automatically, when there is no profile to import it, (or call a command from it)?

As proof, I ran this code:

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

To get this:

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

I have gone through all of https://stackoverflow.com/a/23942543/288393:

  • No call to Import-Module for PSReadline is made because there are no profiles to call it.
  • No commands within PSReadline module are made because, as before, there are no profiles to call it.

Can someone explain this behavior?

Community
  • 1
  • 1
Tahir Hassan
  • 5,715
  • 6
  • 45
  • 65

2 Answers2

4

There is special code in the console host to load PSReadline if the process is interactive. You can see the code here.

Jason Shirk
  • 7,734
  • 2
  • 24
  • 29
1

PSReadline is located in a pre-defined module folder C:\Program Files\WindowsPowerShell\Modules, because it's here PowerShell's automatic cmdlet discovery and module loading process will pick the module up and load it when any functions within it are called. That process added in PS v3.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • Although what you say about automatic cmdlet discovery is true, this is not how PSReadline is automatically loaded. – Tahir Hassan Nov 29 '16 at 19:40