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 …


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
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
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
December 2013