Variable commands
The following commands are used to work with variables:
Clear-Variable
Get-Variable
New-Variable
Remove-Variable
Set-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.
Clear-Variable
The Clear-Variable
command removes the value from any existing variable. Clear-Variable
does not remove the variable itself. For example, the following example calls Write-Host
twice: on the first occasion, it writes the variable value; on the second occasion, it does not write anything:
PS> $temporaryValue = "Some-Value"
PS> Write-Host $temporaryValue -ForegroundColor Green
Some-Value
PS> Clear-Variable temporaryValue
PS> Write-Host $temporaryValue -ForegroundColor Green
Get-Variable
The Get-Variable
command provides access to any variable that has been created in the current session as...