PowerShell – Environment Customization – Prompt

Background

By default, when one initiates Powershell, the environment prompt takes upon the current folder.

Default Prompt

Customization

Outline

  1. Determine the name of our Powershell Profile file
  2. Edit existing file or create a new one
    • Add function called prompt

Get Profile file

Syntax

powershell -Command "Write-Host('Profile file is {0}', $profile);"

Output

Textual


C:\Users\dadeniji\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

 

Edit Profile file

Sample


function prompt
{
	[string] $prompt;
	
	$prompt = ">";
	
	return($prompt);
	
}

Validate

In a new command shell, launch powershell…

And, irrespective of our current folder, we will be greeted with “PS>”.

References

  1. Microsoft
    • Microsoft Technet
      • Scripting Guy
        • Change the Powershell Prompt
          Link
  2. Robert Sheldon
    • ITProToday
      • PowerShell Basics: Console Configuration
        How to customize the PowerShell console
        Link