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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.