The Set variable allows you to change the value and certain aspects of the created variable. For example, the following sets the value of an existing variable:
$objectCount = 23 Set-Variable objectCount -Value 42
It isn't common to see the Set variable being used in this manner; it is simpler to assign the new value directly, as was done when the variable was created. As with the New variable, much of the Set variable's utility comes from the additional parameters it offers, as shown in the following examples.
Setting a description for a variable is effected as follows:
Set-Variable objectCount -Description 'The number of objects in the queue'
Rendering a variable private is effected as follows:
Set-Variable objectCount -Option Private
Private scope
Private scope is accessible using $private:objectCount. The Set variable may be used but is not required.
Private scope is accessible using $private:objectCount. The Set variable may be used but is not required.