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
New-Variable gives more control over the created variable. For example, you may wish to create a constant, a variable which cannot be changed after 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, its properties, and attempts to remove the variable, as shown here:
PS> $startTime = Get-Date
Cannot overwrite variable startTime because it is read-only or constant.
At line:1 char:1
+ $startTime = Get-Date
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (startTime:String) [], SessionStateUnauthorizedAccessException
+ FullyQualifiedErrorId : VariableNotWritable
A variable cannot be changed into a constant after creation.