Easily add timestamp to PowerShell output

With a simple filter a timestamp can be added to any output.

John Savill

August 28, 2016

1 Min Read
Easily add timestamp to PowerShell output

Q. How can I easily add a timestamp to any text output in PowerShell?

A. Filters are a useful capability that can manipulate incoming objects and is really just a function that only has a process scriptblock and it runs once for each incoming object making it useful when evaluating large amounts of data. For example below is an example filter that simply adds a timestamp to any text to sent to it:

filter timestamp {"$(Get-Date -Format G): $_"}

I can then send output to the filter via the pipeline, for example:

PS C:> write-output "hello world" | timestamp8/10/2016 3:45:22 PM: hello world

Note that the time was added to the start of the text.

About the Author(s)

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like