Computer Library windows 2008 exchange server power shell security register

Format a Date for Output

1. Problem
You want to control the way that PowerShell displays or formats a date.
2. Solution
To control the format of a date, use one of the following options:
The Get-Date cmdlet’s –Format parameter:
PS >Get-Date -Date “05/09/1998 1:23 PM” -Format “dd-MM-yyyy @ hh:mm:ss”
09-05-1998 @ 01:23:00
PowerShell’s string formatting (–f) operator:
PS >$date = [DateTime] “05/09/1998 1:23 PM”
PS >”{0:dd-MM-yyyy @ hh:mm:ss}” [...]


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 [...]