Compartir a través de


Get-Variable

Gets the variables in the current console.

Sintaxis

Default (Es el valor predeterminado).

Get-Variable
    [[-Name] <String[]>]
    [-ValueOnly]
    [-Include <String[]>]
    [-Exclude <String[]>]
    [-Scope <String>]
    [<CommonParameters>]

Description

The Get-Variable cmdlet gets the PowerShell variables in the current console. You can retrieve just the values of the variables by specifying the ValueOnly parameter, and you can filter the variables returned by name.

Ejemplos

Example 1: Get variables by letter

This command gets variables with names that begin with the letter m. The command also gets the value of the variables.

Get-Variable m*

Example 2: Get variable values by letter

This command gets only the values of the variables that have names that begin with m.

Get-Variable m* -ValueOnly

Example 3: Get variables by two letters

This command gets information about the variables that begin with either the letter M or the letter P.

Get-Variable -Include M*,P*

Example 4: Get variables by scope

The first command gets only the variables that are defined in the local scope. It is equivalent to Get-Variable -Scope Local and can be abbreviated as gv -s 0.

The second command uses the Compare-Object cmdlet to find the variables that are defined in the parent scope (Scope 1) but are visible only in the local scope (Scope 0).

Get-Variable -Scope 0
Compare-Object (Get-Variable -Scope 0) (Get-Variable -Scope 1)

Parámetros

-Exclude

Specifies an array of items that this cmdlet excludes from the operation. Wildcards are permitted.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:True
DontShow:False

Conjuntos de parámetros

(All)
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-Include

Specifies an array of items upon which the cmdlet will act, excluding all others. Wildcards are permitted.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:True
DontShow:False

Conjuntos de parámetros

(All)
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-Name

Specifies the name of the variable. Wildcards are permitted. You can also pipe a variable name to Get-Variable.

Propiedades del parámetro

Tipo:

String[]

Valor predeterminado:None
Admite caracteres comodín:True
DontShow:False

Conjuntos de parámetros

(All)
Posición:0
Mandatory:False
Valor de la canalización:True
Valor de la canalización por nombre de propiedad:True
Valor de los argumentos restantes:False

-Scope

Specifies the variables in the scope.The acceptable values for this parameter are:

  • Global
  • Local
  • Script
  • A number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent)

Local is the default. For more information, see about_Scopes.

Propiedades del parámetro

Tipo:String
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

(All)
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

-ValueOnly

Indicates that this cmdlet gets only the value of the variable.

Propiedades del parámetro

Tipo:SwitchParameter
Valor predeterminado:None
Admite caracteres comodín:False
DontShow:False

Conjuntos de parámetros

(All)
Posición:Named
Mandatory:False
Valor de la canalización:False
Valor de la canalización por nombre de propiedad:False
Valor de los argumentos restantes:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Entradas

String

You can pipe a string that contains the variable name to this cmdlet.

Salidas

PSVariable

By default, this cmdlet returns a AutomationPSVariable object for each variable that it gets. The object type depends on the variable.

Object

When you specify the ValueOnly parameter and the specified variable's value is a collection, this cmdlet returns a [System.Object[]]. This behavior prevents normal pipeline operation from processing the variable's values one at a time. A workaround to force collection enumeration is to enclose the Get-Variable command in parentheses.

Notas

Windows PowerShell includes the following aliases for Get-Variable:

  • gv

  • This cmdlet does not manage environment variables. To manage environment variables, you can use the Environment provider.