© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
V. SukhijaPowerShell Fast Track https://doi.org/10.1007/978-1-4842-7759-1_2

2. Date and Logs

Vikas Sukhija1  
(1)
Waterloo, ON, Canada
 

To create scripts, it is essential to understand how to use the date and time cmdlet to timestamp different types of operations, such as creating a time-stamped log file. I will share a cheat function that you can utilize inside your scripts to create a time-stamped log as well as time-stamped entries inside the script.

Let’s go through some date and time illustrations before utilizing the Write-Log function that I have already created for you. (This is the first actual cheat code that you will utilize in your scripts!)

The

Get PowerShell Fast Track: Hacks for Non-Coders now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.