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?


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.

  • 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

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

function prompt { "$pwd>" }

Try the following:

$CurrentDir = $(get-location).Path;
  • above code is also a way of getting the location. – Narottam Goyal Jul 25 '16 at 5:03

Nowadays, this works fine:

echo "$PWD"

which works differently than

echo $PWD

Just don't forget the quotes :) Sample output below.

PS C:\Users\user name> echo $PWD

C:\Users\user name

PS C:\Users\user name> echo "$PWD"
C:\Users\user name
PS C:\Users\user name>
(Get-Item -Path ".\").FullName

To show only the current directory in PowerShell (or pwsh), put this in your profile.ps1:

function prompt { 'PS - ' + (get-item .).name + ' >' }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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