How to one show the current directory in PowerShell

powershell

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?

Best Answer

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.