Here’s a useful Powershell trick.

The prompt() function is used to generate the text shown as the Powershell prompt in an interactive window.

By redefining prompt() you can make some useful changes, taking control of the prompt display. Put the changes into your Powershell profile, and they become permanent.

For example, the following version of prompt() does two things.

Firstly, it modifies the title of the current Powershell window to reflect the current directory, making it easier to find the window you want when you have several Powershell windows open.

Secondly, it puts the machine name into the prompt - useful for me as I typically have four or five remote desktop windows open to different servers; anything that helps me avoid running a script on the wrong machine is worth its weight in gold.

# Define a new prompt
function prompt {
    $Host.UI.RawUI.WindowTitle = $pwd
    "$env:computername $pwd>" 
}

What might you put in your prompt() function?

Some links …

Comments

blog comments powered by Disqus
Next Post
Fractals for Christmas  21 Dec 2013
Prior Post
Deploying with a bin folder  05 Nov 2013
Related Posts
Old blog posts, restored  26 Oct 2025
Better Table Tests in Go  21 Oct 2025
Error assertions  26 Apr 2025
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Archives
December 2013
2013