New

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-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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.150.163