Getting a timestamp

In this recipe, we simply get the system's current timestamp.

How to do it...

This is how we will get the timestamp:

  1. Open PowerShell ISE as an administrator.
  2. Add the following script and run it:
    $timestamp = Get-Date -Format "yyyy-MMM-dd-hhmmtt"
    
    #display timestamp
    $timestamp

Here is a sample result:

How to do it...

How it works...

Often, we find ourselves needing the timestamp to append to different files we create or modify. To get the timestamp in PowerShell, we simply have to use the Get-Date cmdlet, which gives the following default format:

How it works...

To change ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.