Get the System Date and Time

1. Problem

You want to get the system date.

2. Solution

To get the system date, run the command Get-Date.

3. Discussion

The Get-Date command generates rich object-based output, so you can use its result for many date-related tasks. For example, to determine the current day of the week:

        PS >$date = Get-Date
        PS >$date.DayOfWeek
        Sunday

For more information about the Get-Date cmdlet, type Get-Help Get-Date.

For more information about working with classes from the .NET Framework, see Section 3.4, “Work with .NET Objects.”

Tags: , , , , , , , ,