Configure PowerShell prompt to always display date and time

Sometimes, we may want to know when a particular PowerShell command was executed in our current shell. Simply scrolling through the PowerShell history will not help you as it just shows the commands. Having current date and time as part of PowerShell prompt improves the situation to a greater level. It also helps you in recording your changes in proper way.

Here is a small piece of code which helps you to add current date time to PowerShell prompt. You can change the formatting of the date and time to meet your requirements. But make sure to keep the function name same:

function prompt 
{ 
 "PS " + $(get-location) + " [$(Get-Date)]> " 
}

My personal preference is to add this to PowerShell profile, so that it auto-runs each time I start a new PowerShell session.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s