Wednesday, June 19, 2013

Insert timestamps into PowerShell outputs



For your PowerShell tasks, you can have a timestamp entered in series so you can determine how long a single step occurs or to use as a logging mechanism for your scripts. I find this handy in Graphical PowerShell when I’m testing scripts. To insert a timestamp, enter one of the following commands as a single line within your .ps1 file:
Command
Output example
“$(Get-Date -format g) Start logging”
2/5/2008 9:15 PM
“$(Get-Date -format F) Start logging”
Tuesday, February 05, 2008 9:15:13 PM
“$(Get-Date -format o) Start logging”
2008-02-05T21:15:13.0368750-05:00

There are many other formats for the Get-Date command, but these three options would generally suite most applications for timestamp purposes.

No comments:

Post a Comment