Get PowerShell variables in the current console.

      Get-Variable [[-Name] String[] ]
         [-Include string] [-Exclude string] 
            [-valueOnly] [-scope string] [CommonParameters]
       The name of the variable(s), may be piped.

   -include string
       Retrieve only the specified items.
       Wildcards are permitted.

   -exclude string
       Omit the specified items. Wildcards are permitted.
       Get only the value of the variable.

   -scope string
       The scope in which this alias is valid. 
       Valid values are "Global", "Local", "Private" or "Script", or 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, type "get-help about_scope".

Standard Aliases for Get-Variable: gv


Display variables with names that begin with var:

PS C:\> get-variable p*

Display only the values (compare with selecting the value property from the object):

PS C:\> get-variable p* -valueOnly
PS C:\> get-variable p* | select value

Display variables that have the ReadOnly option set:

PS C:\> get-variable | Where-Object {$_.Options -like '*ReadOnly*'}

Display and sort variables that begin with either the letter 'S' or the letter 'P':

PS C:\> get-variable -include s*,p* | sort-object name

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it" ~ Brian W. Kernighan

Related PowerShell Cmdlets

Clear-Variable - Remove the value from a variable.
New-Variable - Create a new variable.
Remove-Variable - Remove a variable and its value.
Set-Variable - Set a variable.
How-to: Automatic variables - Variables created and maintained by PowerShell $_, $Args, $Error, $Home etc.
How-to: Environment variables - Windows environment variables Env:
Equivalent bash command: env - Display, set, or remove environment variables.

Copyright © 1999-2024
Some rights reserved