PowerShell Logo Small

Get-Variable



This is the built-in help made by Microsoft for the command 'Get-Variable', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' 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[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.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 specifying the ValueOnly
parameter, and you can filter the variables returned by name.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293979
Clear-Variable
New-Variable
Remove-Variable
Set-Variable

REMARKS

<

Examples


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

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.










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

PS C:\>Get-Variable m* -Valueonly



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










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

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










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

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