PowerShell Logo Small

Get-Variable



This is the built-in help made by Microsoft for the command 'Get-Variable', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Gets the variables in the current console.

SYNTAX


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



Search powershellhelp.space

DESCRIPTION


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



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113336
Set-Variable
New-Variable
Clear-Variable
Remove-Variable

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-variable m*



Description
-----------
This command displays variables with names that begin with the letter "m". The value of the variables is also displayed.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-variable m* -valueonly



Description
-----------
This command displays only the values of the variables with names that begin with the letter "m".








-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-variable -include M*,P* | sort-object name



Description
-----------
This command gets information about the variables that begin with either the letter "M" or the letter "P". The results are piped to the Sort-Obje
ct cmdlet, sorted by name, and displayed.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-variable -scope 0

C:\PS> compare-object (get-variable -scope 0) (get-variable -scope 1)



Description
-----------
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 abbrevi
ated 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 th
e local scope (Scope 0).