Comments these days:

Powershell-Tips has crossed 4,00,000 views. If you are stuck with any Powershell script, do send mail to me.

Thursday, February 2, 2012

Changing Powershell Prompt

When you open Powershell, you get a prompt like - PS C:\Users\Administrator>. The prompt is very good, but after few days of working you feel to have a change. But the good old command 'prompt' does not work in Powershell.

For those who don't know how to change prompt in Command Prompt, you can try below command Prompt -
prompt $$
prompt $p$g

The same command does not work in Powershell. I tried it very early days and skipped when it did not work. So, the question is - How to change Prompt in Powershell ?

You need to create function named prompt to change the prompt easily. Follow the below steps -
1. Open Command-Prompt of Powershell.
2. Run the below -
function prompt { "Posh >" ; return " " }

The above command you need to run every time you run Powershell. So, this will be a cumbersome approach. So, let's try another approach - Change your profile which is a Powershell script that runs every time.
1. Find the location of $profile using below command -
echo $profile
2. You might get a path like -
3. This path does not exists usually. You can goto location Documents and create a folder named WindwosPowershell and file mentioned above. Create it and move to next step.
4. Run the command -
notepad $profile
5. Copy and paste below script in the notepad and save it -

  1. function prompt
  2. {
  4. Write-Host ( "Posh (" + $("000000000${GLOBAL:CNT_OF_PRMT} > ").tostring().substring($("000000000${GLOBAL:CNT_OF_PRMT}").length-4 , 4) + ") > ") -foregroundcolor white -nonewline
  5. return " "
  6. }
You might see a command prompt with a line number -
Posh (0064) >
Posh (0065) >

Every time we press enter a value is increased. You can change the foregroundcolor of your choice.
Isn't this glamorous! I like it!

No comments:

Post a Comment