Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 1.0 » Get-Date

Get-Date - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Get-Date

Description
Get current date and time

Usage
Get-Date [[-date] DateTime]
         [-displayHint {Date | Time | DateTime}]
           {[-format string] | [-uFormat string]}
              [-year int] [-month int] [-day int] [-hour int]
                 [-minute int] [-second int] [CommonParameters]

Options
-date DateTime
        By default, Get-Date returns the current system date and time.
        The -date parameter allows you to specify
        (usually via the pipeline) a specific date and time. 

   -displayHint DisplayHintType
        Display only the Date, only the Time or the DateTime.
		 This does not affect the DateTime object that is retrieved.

   -format string
        Display the date and time in the .NET format
        as indicated by String representing a format specifier. 
        
   -uFormat string
        Displays the date and time in Unix format.

   -year -month -day -hour -minute -second 
        These allow you to set individual items to be displayed in place
        of the current date/time. e.g. you could set the time to 12:00

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
Retrieve the current date and time, but display only the date:

PS C:\>get-date -DisplayHint date

Retrieve the current date and time, display as a General short date/time:

PS C:\>get-date -format g

Display the day of the year:

PS C:\>(get-date).dayofyear

Display daylight savings and UTC:

PS C:\>$a = get-date
$a.IsDaylightSavingTime()
$a.ToUniversalTime()

Display the bios date of a remote machine using WMI:

PS C:\>$a = get-wmiobject win32_bios -computer SERVER64
$a | format-list -property Name, @{Label="BIOS Date "; `
Expression={$_.ConvertToDateTime($_.ReleaseDate)}}

The backtick character (`) is the line continuation character