Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'd like to have the current working directory show on the powershell command line, as would be done in a (for example) CMD prompt. How can I do so?

share|improve this question
add comment

2 Answers

up vote 14 down vote accepted

Check this out: http://mshforfun.blogspot.com/2006/05/perfect-prompt-for-windows-powershell.html

Basically, you can create a 'profile' file called Microsoft.PowerShell_profile.ps1 which will run every time you start powershell.

Depending on whom you want it to run for, there are several folders you can put this file in (explained in the link above). If it's just for yourself, you can create a folder called WindowsPowerShell in your My Documents folder, and put it there.

If you put this function in that file:

function prompt
{
    "PS " + $(get-location) + "> "
}

It will make your prompt look like this:

PS C:\directory\path\here>

There's a whole lot of other stuff you can put in it, but that's the basics.

NOTE: before you can use the profile script, you'll need to run "set-executionpolicy remotesigned" from the powershell - this will allow you to run unsigned scripts written locally on the computer and signed scripts from others.

share|improve this answer
    
Doesn't seem to work for Visual Studio's add-in :( Oh well. –  Billy ONeal Jan 26 '11 at 4:08
    
@BillyONeal: Check the value of $profile.CurrentUserCurrentHost and $profile.CurrentUserCurrentHost to see what (user) profile scripts are valid. Different hosts (e.g. VS vs. ISE) have a different value for $profile.CurrentUserCurrentHost –  Richard Jan 26 '11 at 10:51
add comment

Simple, add the following to your profile.ps1 file (under your My Documents\WindowsPowerShell folder):

function prompt { "$pwd>" }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.