Variable provider
PowerShell includes a provider and a drive, which allows variables to be listed, created, and changed using Get-ChildItem
, Test-Path
, and so on.
Get-ChildItem
may be used to list all the variables in the current scope by running the command shown as follows:
Get-ChildItem variable:
The output will include the built-in variables, as well as any variables created by modules that might have been imported.
As the provider behaves much like a filesystem, Test-Path
may be used to determine whether a variable exists. Get-Variable
may be used instead, but Get-Variable
will throw an error if the variable does not exist:
Test-Path variable:\VerbosePreference
Set-Item
may be used to change the value of a variable or create a new variable:
Set-Item variable:\new -Value variable
Get-Content
can also be used to retrieve the content of a variable:
Get-Content variable:\OutputEncoding
The backslash character used in the preceding examples...