Tahir Hassan
Tahir Hassan

Reputation: 5817

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

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:

Can someone explain this behavior?

Upvotes: 3

Views: 566

Answers (2)

Jason Shirk
Jason Shirk

Reputation: 8019

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

Upvotes: 4

henrycarteruk
henrycarteruk

Reputation: 13227

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.

Upvotes: 1

Related Questions