The Windows PowerShell Variable Provider lets you get, add, change, clear, and delete Windows PowerShell variables in the current console.
The Windows PowerShell Variable Provider supports the variables that Windows PowerShell creates, including the automatic variables, the preference variables, and the variables that you create.
The Variable Provider is a flat namespace that contains only the variable objects. The variables have no child items.
Most of the variables are instances of the System.Management.Automation.PSVariable class. However, there are some variations. For example, the "?" variable is a member of the QuestionMarkVariable class, and the "MaximumVariableCount" variable is a member of the SessionStateCapacityVariable class.
The Variable Provider exposes its data store in the Variable: drive. To work with variables, you can change your location to the Variable: drive --powershell--"set-location variable:"--powershell--, or you can work from any other Windows PowerShell drive. To reference a variable from another location, use the drive name --powershell--Variable:--powershell-- in the path.
Windows PowerShell includes a set of cmdlets designed especially to view and to change variables:
-- Get-Variable
-- New-Variable
-- Set-Variable
-- Remove-Variable
-- Clear-Variable
When you use these cmdlets, you do not need to specify the Variable: drive in the name.
The Variable Provider supports all of the cmdlets whose names contain the Item noun --powershell--the Item cmdlets--powershell--, except for Invoke-Item. The Variable Provider supports the Get-Content and Set-Content cmdlets. However, it does not support the cmdlets whose names contain the ItemProperty noun --powershell--the ItemProperty cmdlets--powershell--, and it does not support the Filter parameter in any cmdlet.
You can also use the Windows PowerShell expression parser to create, view, and change the values of variables without using the cmdlets. When working with variables directly, use a dollar sign --powershell--$--powershell-- to identify the name as a variable and the assignment operator --powershell--=--powershell-- to establish and change its value. For example, "$p = Get-Process" creates the "p" variable and stores the results of a "Get-Process" command in it.
All changes to the variables affect the current session only. To save the changes, add the changes to the Windows PowerShell profile, or use Export-Console to save the current console.