Variables
A variable is a storage location that developers can use to store information with a so-called value. Variables always have names that allow you to call them independently of the values that are stored within. In PowerShell, the $ sign at the beginning indicates a variable:
> $i = 1
> $string = "Hello World!"
> $this_is_a_variable = "test"
Variables are great for storing simple values, strings, and also the output of commands:
> Get-Date
Monday, November 2, 2020 6:43:59 PM
> $date = Get-Date
> Write-Host "Today is" $date
Today is 11/2/2020 6:44:40 PM
As you can see in these examples, not only can we store strings and numbers within a variable, we can also store the output of a cmdlet such as Get-Date and reuse it within our code.
Data types
In contrast to other scripting or programming languages, you don’t necessarily need to define the data type for variables. When defining a variable...