This is the first in a two-part series on working with dates in Windows PowerShell. As with any PowerShell concept its best to start out small, and then work your way into the more complex pieces. PowerShell is like that. You can do most things very simply and get the job done. But, as you learn more about a feature, you realize that there is extra power hidden that can be tapped to customize and extend. Working with a seemingly simple concept like just displaying the current date and time can turn into a scripter's masterpiece if you take the time to learn the entire breadth of the function.

PowerShell comes with an embedded cmdlet called Get-Date that does exactly as the function suggests, it gets the date (which includes the day, date, and time).

A simple one-liner in the PowerShell console will do it:

Get-Date

As you can see from my output, the date is retrieved and displayed. It's informative, accurate, and simple:

But, what if you want the date displayed in a different way? Obviously, the basic formatting of the Get-Date cmdlet alone would be semi-difficult to parse as a variable for the rest of a script. For example, say you are writing a script that retrieves all files in a specific folder, makes a modification to each one, and then resets the date flag. Parsing the basic output for the Get-Date cmdlet would take a bit longer than if the date actually read: 7.16.2013.

In the next article in the series, we'll jump into customizing the date display with quick formatting and custom formatting, allowing you to produce a date to display in any way you prefer.

Part 2:  PowerShell One-Liner: Quick Customization of the Date and Time Display