Variable commands
The variable commands may be used to explore and interact with variables defined in PowerShell. However, these commands are rarely used to declare variables when writing scripts or functions.
PowerShell optimizes code when it can, specifically in this section around the use of local variables. Using the *-Variable
commands in a script block disables optimization, which will have an impact on the performance of a script.
The following commands are used to work with variables:
Get-Variable
New-Variable
Set-Variable
Remove-Variable
Clear-Variable
When using the variable commands, the $
preceding the variable name is not considered part of the name; $
tells PowerShell what follows is a variable name.
Get-Variable
The Get-Variable
command provides access to any variable that has been created in the current session as well as the default (automatic) variables created by PowerShell. For further information on automatic...