NAME
Get-Variable
SYNOPSIS
Gets the Variables in the current console.
SYNTAX
Get-Variable [[-Name] <string[]>] [-Exclude <string[]>] [-Include <string[]>] [-Scope <string>] [-ValueOnly] [<CommonParameters>]
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.
PARAMETERS
-Exclude <string[]>
Omits the specified items. Wildcards are permitted.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Include <string[]>
Specifies only the items upon which the cmdlet will act, excluding all others. Wildcards are permitted.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Name <string[]>
Specifies the name of the Variable.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-Scope <string>
Gets only the Variables in the specified scope. Valid values are “Global”, “Local”, 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 information, see about_scopes.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ValueOnly [<SwitchParameter>]
Gets only the value of the Variable.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
“Get-Help about_CommonParameters“.
INPUTS
System.String
You can pipe a string that contains the Variable name to Get-Variable.
OUTPUTS
Variable object
Get-Variable returns a System.Management.Automation Variable object for each Variable that it gets. The object type depends on the Variable.
NOTES
This cmdlet does not manage Environment Variables. To manage Environment Variables, you can use the Environment Variable provider.
————————– 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-Object 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 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).
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113336
Set-Variable
New-Variable
Clear-Variable
Remove-Variable