How can one show the current directory in PowerShell?

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.


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;

Tags:

Powershell