PDQ.com mobilePDQ.com desktop
Support

Get-Variable

Gets the variables in the current console.
Get-Variable [[-Name] <String[]>] [-Exclude <String[]>] [-Include <String[]>] [-Scope <String>] [-ValueOnly][<CommonParameters>]

The Get-Variable cmdlet gets the Windows 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.

Parameters

-Exclude <String[]>

  • Default value is None
  • Accepts pipeline input False

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

-Include <String[]>

  • Default value is None
  • Accepts pipeline input False

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

-Name <String[]>

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

-Scope <String>

  • Default value is None
  • Accepts pipeline input False

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.

-ValueOnly [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

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

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs
System.String
You can pipe a string that contains the variable name to Get-Variable .
Outputs
System.Management.Automation.PSVariable
This cmdlet returns a System.Management.AutomationPSVariable object for each variable that it gets. The object type depends on the variable.
Examples
  1. Get variables by letter:
    PS C:\> Get-Variable m*
    

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

  2. Get variable values by letter:
    PS C:\> Get-Variable m* -ValueOnly
    

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

  3. Get variables by two letters:
    PS C:\> Get-Variable -Include M*,P*
    

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

  4. Get variables by scope:
    PS C:\> Get-Variable -Scope 0
    PS C:\> Compare-Object (Get-Variable -Scope 0) (Get-Variable -Scope 1)
    

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

Additional Notes
 * This cmdlet does not manage environment variables. To manage environment variables, you can use the 
 environment variable provider.

 *
Back to PowerShell Command list
PDQ.com
© 2020 PDQ.com Corporation

Products

  • Deploy
  • Inventory
  • Enterprise SL
  • Pricing
  • Downloads
  • Licensing
  • Buy