Databases Reference
In-Depth Information
❑
-include <string[]>
: Specifies only the items upon which the cmdlet will act, excluding all oth-
ers. A string array containing names is passed, and wildcards are permitted. If the same string
array is passed to this parameter and the -
name
parameter, the same set of variables will be
returned. The only difference is the order in which the variables are returned.
❑
-exclude <string[]>
: Excludes the specified items. A string array containing names is passed,
and wildcards are permitted.
❑
-valueOnly <SwitchParameter>
: Returns only the values of the variables.
You can filter the variables based on their optional properties. The following command uses the
Where-Object
cmdlet to filter out read-only variables whose options are equal to
ReadOnly
:
Get-Variable | Where-Object {$_.options -eq 'ReadOnly'}
As shown in Figure 5-42, the read-only variable
rovar
defined earlier was returned.
Figure 5-42
Set-Variable:Setsthevalueofvariablesorchangesthepropertiesofthe
variables
Set-Variable [-name] <string[]> [[-value] <Object>] [-include <string[]>]
[-exclude <string[]>] [-scope <string>] [-description <string>] [-option {<None> |
<ReadOnly> | <Constant> | <Private> | <AllScope>}] [-force] [-passThru]
[-whatIf] [-confirm] [<CommonParameters>]
You have seen all the parameters in the
New-Variable
and
Get-Variable
cmdlets except the
force
parameter. This parameter forces the cmdlet to make the best attempt at setting the variable. This param-
eter is needed to change the value of a read-only variable. However, it has no effect on a constant. For
example, to change the value of the read-only variable
rovar
that was defined earlier, run the following
command:
Set-Variable rovar -value 5 -force
$rovar
Figure 5-43 shows that the value of the read-only variable
rovar
is changed to
5
.
Remove-Variable:Removesvariables
Remove-Variable [-name] <string[]> [-include <string[]>] [-exclude <string[]>]
[-scope <string>] [-force] [-whatIf] [-confirm] [<CommonParameters>]
Search WWH ::
Custom Search