≡ Menu

PsTip# Add date and time to Powershell Prompt

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. I thought having current date and time as part of poweshell 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)]> "            

Usage and Output:

You can clearly see in the above picture that, I simply copy pasted the code into powershell prompt and it started showing the date time stamp in the prompt section. The date and time are changing when switched to a new directory or simply pressed enter or when entering a command.

This is very helpful for tracking. Add this to your powershell profile to get this prompt every time you open powershell window.

{ 2 comments… add one }
  • al May 27, 2016, 6:15 pm

    great tip ! Can you do the same on the command line ? (cmd)

Leave a Comment