Search code examples
powershellpowershell-remoting

Is it possible to keep the same prompt for PSSessions?


When I use Enter-PSSession with Powershell I get a new prompt like

[HOSTNAME]:>

This is nice, but I'm wondering if there's a way to have it not do that, and just default to the regular Powershell prompt.

The reason I ask is that I already have the hostname set in my normal prompt function, so my prompt ends up looking like

[HOSTNAME] <PWD> [HOSTNAME]>

which is sort of unnecessary.

Is there any way to override this feature?


Solution

  • You can redefine your prompt for remote session like this :

    $session = New-PSSession MyRemoteServer
    Invoke-Command -Session $session -ScriptBlock {
        function prompt { your_prompt_here }
    }
    Enter-PSSession -Session $session
    

    look here for a prompt function that override the pre-prompt [computername]: