Get-Variable (Microsoft.PowerShell.Utility) - PowerShell (2024)

  • Reference

Gets the variables in the current console.

Syntax

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

Description

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

Examples

Example 1: Get variables by letter

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

Get-Variable m*

Example 2: Get variable values by letter

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

Get-Variable m* -ValueOnly

Example 3: Get variables by two letters

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

Get-Variable -Include M*,P*

Example 4: Get variables by scope

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 theparent scope (Scope 1) but are visible only in the local scope (Scope 0).

Get-Variable -Scope 0Compare-Object (Get-Variable -Scope 0) (Get-Variable -Scope 1)

Parameters

-Exclude

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

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Include

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

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:True

-Name

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

Type:String[]
Position:0
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:True

-Scope

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 currentscope and 1 is its parent)

Local is the default.For more information, see about_Scopes.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ValueOnly

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

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

String

You can pipe a string that contains the variable name to this cmdlet.

Outputs

PSVariable

By default, this cmdlet returns a AutomationPSVariable object for each variable that it gets.The object type depends on the variable.

Object[]

When you specify the ValueOnly parameter and the specified variable's value is a collection,this cmdlet returns a [System.Object[]]. This behavior prevents normal pipeline operation fromprocessing the variable's values one at a time. A workaround to force collection enumeration is toenclose the Get-Variable command in parentheses.

Notes

PowerShell includes the following aliases for Get-Variable:

  • All platforms:

    • gv
  • This cmdlet does not manage environment variables. To manage environment variables, you can usethe environment variable provider.

Get-Variable (Microsoft.PowerShell.Utility) - PowerShell (2024)
Top Articles
Nullity
How soaking your feet in hot water could help with migraines
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Van Hayes

Last Updated:

Views: 5644

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Van Hayes

Birthday: 1994-06-07

Address: 2004 Kling Rapid, New Destiny, MT 64658-2367

Phone: +512425013758

Job: National Farming Director

Hobby: Reading, Polo, Genealogy, amateur radio, Scouting, Stand-up comedy, Cryptography

Introduction: My name is Van Hayes, I am a thankful, friendly, smiling, calm, powerful, fine, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.