Basics with Windows Power Shell by Prometheus MMS - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

1.2 Listing Date and Time Information

   As you might expect, the Get-Date cmdlet enables you to retrieve the current date and time. As you might also expect, there are a few other interesting tricks you can do with Get-Date, some of which we’ll show you momentarily.

   Let’s start with the simplest scenario first. If all you want is the current date and time then simply call Get-Date without any additional parameters:

Get-Date

In return, you’ll get back something similar to this:

Wed May 10 10:07:25 2006

Ah, but suppose you want only the date, not the date and the time? Then just use the displayhint parameter and specify date:

Get-Date -displayhint date

Or, if you’d prefer just the time:

Get-Date -displayhint time

You can also use Get-Date to create a date-time object for any date/time. For example, this command creates a variable named $A that maps to 12:00 AM on May 1, 2006:

$A = Get-Date 5 / 1/2006

What’s that? You need to map $A to 7:00 AM on May 1, 2006? Why not:

$A = Get-Date "5/1/2006 7:00 AM"

Get-Date also includes a number of methods for doing some handy-dandy date arithmetic:

Add Seconds

Add Minutes

Add Hours

Add Days

Add Months

Add Years

Need to know the date/time 137 minutes from now? This command will show you: ( Get-Date).AddMinutes (137)

Find Your Next Great Read

Describe what you're looking for in as much detail as you'd like.
Our AI reads your request and finds the best matching books for you.

Showing results for ""

Popular searches:

Romance Mystery & Thriller Self-Help Sci-Fi Business