First thing what I do in Powershell Console. Powershell prompt!!!

Hi, Damian Garbus here. It’s awesome to have you here. I want to share you the first thing what I do after starting PowerShell Console in new my desktop or server. This thing is changing Powershell prompt function. If don’t know what is “prompt”, you can check where my graphics about parts of PowerShell console here. Prompt is the directory path where user currently is. 

First of all read before

What is Powershell prompt

By default, prompt show for us where currently we are. It’s very helpful but If the path is very long, it makes work a bit difficult. See how it work 

 

An unnecessary path to change

When you run PowerShell console PowerShell load function named “prompt”. Consequently, this function load our current path during start PowerShell but also load during using PowerShell console. By default, it writes in our console full path of directory where currently we are. Let’s check default prompt function in your PowerShell console.  

(Get-Command prompt).scriptblock


 

 

How to change it 

The path what is displayed in PowerShell Console is anything else than function which can be change by anyone.  Ok, but where you can change it. New prompt function you have to write in $profile. If you don’t know what is PowerShell profile check my last Post. I always change it to show me only current folder name (not all path). Check this out. 

 

notepad $profile
function prompt {
"PS [$env:COMPUTERNAME]> $(($pwd -split '\\')[-1]) >"
}

But I want to know my current path? 

Solution are two. First of all, use “pwd” command. Finally second, (recommended by me) is modify prompt to show full path in Windows title.  

 

function prompt {
$host.ui.RawUI.WindowTitle = $(get-location)
"PS [$env:COMPUTERNAME]> $(($pwd -split '\\')[-1]) >"
}

 

Conclusion 

Prompt is a function which show us current full path in Powershell console. As a result, you can modify this function to your own and have all this information that you want. It can be modified by everyone. Please comment if you have your own prompt function. 

Enjoy. 

 

Get Access to Poshland Resources for FREE!!!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailerLite ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.