Explain Get-Date function in PowerShell.

PowerShellMicrosoft TechnologiesSoftware & Coding

Get-Date function in PowerShell is to get the current system date and time. For example, when you type simply Get-Date, the output will be,

Get-Date


PS C:\WINDOWS\system32> Get-Date
18 March 2020 19:17:03

When you check the type of the (Get-Date) function, it is DateTime.

(Get-Date).GetType()
PS C:\WINDOWS\system32> (Get-Date).GetType()
IsPublic IsSerial    Name       BaseType
-------- --------    ----       --------
True     True        DateTime    System.ValueType

When you check all the properties of the (Get-Date).

PS C:\WINDOWS\system32> Get-Date | fl * DisplayHint : DateTime
DateTime    : 18 March 2020 19:32:32
Date        : 18-03-2020 00:00:00
Day         : 18
DayOfWeek   : Wednesday
DayOfYear   : 78
Hour        : 19
Kind        : Local
Millisecond : 793
Minute      : 32
Month       : 3
Second      : 32
Ticks       : 637201567527939152 TimeOfDay : 19:32:32.7939152
Year        : 2020

You can also get the individual above property. For example,

PS C:\WINDOWS\system32> (Get-Date).DayOfWeek
Wednesday


PS C:\WINDOWS\system32> (Get-Date).DayOfYear
78
raja
Published on 20-Mar-2020 06:51:49
Advertisements