Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Powershell in Windows 7. How to configure Powershell so that it only displays the current folder name (instead of the full path) in the shell prompt?

For example, Instead of C:\folder\directory\name>, I want name>.

share|improve this question
up vote 20 down vote accepted

You have to customize the prompt function in your PowerShell profile (%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1); it may be blank or even not exist if you have never modified it before.

  1. Open your profile (e.g., open the aforementioned file or while in PowerShell, Notepad $profile)

  2. Add the following to your profile:

    function prompt {
      $p = Split-Path -leaf -path (Get-Location)
      "$p> "
  3. Save the profile

  4. Restart PowerShell

share|improve this answer
Not quite right. [System.IO.Directory]::GetCurrentDirectory() does not represent powershell's current location, but rather the process working directory, which are not always the same. Replace with Get-Location – zdan Jul 9 '12 at 20:57
+1, but I would use get-location instead of GetCurrentDirectory. Remember that PowerShell does not always mean the file system. Using the registry snap-in, I could use cd hkcu: and now the prompt would be totally off. – vcsjones Jul 9 '12 at 20:58
I don't use PowerShell (it is excruciatingly slow on my system), so I am not familiar with its intricacies. I have changed the call and improved the formatting. – Synetech Jul 9 '12 at 21:01
@Synetech oops, looks like my edit killed your change. – vcsjones Jul 9 '12 at 21:03
@vcsjones, no worries, it's fixed now. And thanks for telling me about the eight-space thing, I have never seen that (and been quiet frustrated). Now I have to find the one or two times in the past that I could have used it and make the change. – Synetech Jul 9 '12 at 21:06

The below single line works fine for me

(Get-Location | Get-Item).Name

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .