How to do it...

First, we will look at converting text into an object from a plain text input at the Terminal. This involves using what is known as a PowerShell Type Accelerator. A PowerShell Type Accelerator is an alias for .NET classes. Using these, we can call .NET classes and use many of their functionalities within PowerShell:

  1. Let's take plain text as input and convert the text into a date object. To check what sort of object your input is, use the Get-Member cmdlet:
PS> '21 June 2018' | Get-Member
Enclosing any text within single quotes defines the text as a non-expanding literal string. No explicit definition is required in this case.
  1. The TypeName says System.String. This confirms that what we entered was plain text. Now, let's ...

Get PowerShell Core for Linux Administrators 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.