Powershell: Customize the prompt

Hi,

the default prompt of the powershell is “PS” and the current working directory:

PS D:\> 

This is set by the prompt function. With the Get-Command command let you can show the prompt functions script code:

PS D:\> Get-Command Prompt
PS D:\> (Get-Command Prompt).ScriptBlock
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) ";

To customize the prompt simply define an own function prompt. For example add a newline before the “>”

function prompt()
{
    "PS $($executionContext.SessionState.Path.CurrentLocation)$("`r`n>" * ($nestedPromptLevel + 1)) ";
}

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.