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
A Tale of Minification  17 Feb 2018
A Productivity Prompt for PowerShell  10 Feb 2018
Test Coverage History  18 Nov 2017
Tracking time  11 Nov 2017
The day my build broke  04 Nov 2017
NuGet and .NET Core  28 Oct 2017
.NET Core Builds  21 Oct 2017
Test Coverage Reporting  07 Oct 2017
Test Coverage with Opencover  30 Sep 2017
NuGet packaging  23 Sep 2017
More powershell posts »
Archives
December 2013
2013