O'Reilly logo

Windows PowerShell™ 2 For Dummies® by Steve Seguis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Going On a Date with PowerShell

In This Chapter

  • Getting a date

  • Performing date calculations

  • Working with time zones

Whether you're scheduling an automated task, generating time stamp–based log file names, or trying to deal with date-related problems such as the infamous Y2K bug or the change in daylight saving time, dates are an important part of many computing tasks. Windows PowerShell builds on top of the rich Date and Time support provided by the .NET Framework and adds a few features such as the capability to use Unix-style formatters to modify how the dates are presented.

In this chapter, you define dates and times and use them in different scenarios such as calculating elapsed time or figuring out daylight savings time. You might not use dates and times as much as you use other data types, but they're very important because they're very relevant to our day-to-day life. Even if you don't need it just now, make a note of this chapter because soon enough you're bound to need it, even if it's something as simple as trying to display the current date and time to screen.

Going On Your First Date

To work with dates and times in Windows PowerShell, you use the Get-Date Cmdlet. It's the Swiss Army Knife of Windows PowerShell dates and times; you use it to find out the current date and time as well as to create date objects to define any arbitrary date. To find out the current date and time, you run Get-Date by itself without any parameters, like this:

Get-Date

When you run this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required