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.


If you would want a more linux like experience, where you want to show only the name of the present working directory and along with date and time, you can use this little code:

function prompt{
"PS " + $(Get-location).Path.Split('\')[-1] + " [$(Get-Date)]> "

Leave a Reply

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

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

Facebook photo

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

Connecting to %s