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