February 2019
Intermediate to advanced
626 pages
15h 51m
English
The New variable can be used to create a new variable:
New-Variable -Name today -Value (Get-Date)
This command is the equivalent of using the following:
$today = Get-Date
The New variable gives more control over the created variable. For example, you may wish to create a constant, a variable that can't be changed following its creation:
New-Variable -Name startTime -Value (Get-Date) -Option Constant
Any attempt to modify the variable after creation results in an error message; this includes changing the variable value or its properties and attempts to remove the variable, as shown here:
PS> $startTime = Get-DateCannot overwrite variable startTime because it is read-only or constant.At line:1 char:1+ $startTime = Get-Date+ ~~~~~~~~~~~~~~~~~~~~~ ...
Read now
Unlock full access