PowerShell Logo Small

Clear-Variable



This is the built-in help made by Microsoft for the command 'Clear-Variable', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Deletes the value of a variable.

SYNTAX


Clear-Variable [-Name] <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<Commo
nParameters>]



Search powershellhelp.space

DESCRIPTION


The Clear-Variable cmdlet deletes the data stored in a variable, but it does not delete the variable. As a result, the value of the variable is N
ULL (empty). If the variable has a specified data or object type, Clear-Variable preserves the type of the object stored in the variable.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113285
Get-Variable
Set-Variable
New-Variable
Remove-Variable

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>clear-variable my* -global



Description
-----------
This command deletes the value of the global variables that begin with "my".








-------------------------- EXAMPLE 2 --------------------------

C:\PS>$a=3

C:\PS>&{ clear-variable a }

C:\PS>$a
3



Description
-----------
These commands demonstrate that clearing a variable in a child scope does not clear the value in the parent scope. The first command sets the val
ue of the variable $a to "3". The second command uses the invoke operator (&) to run a Clear-Variable command in a new scope. The variable is cle
ared in the child scope (although it did not exist), but it is not cleared in the local scope. The third command, which gets the value of $a, sho
ws that the value "3" is unaffected.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>clear-variable -name processes



Description
-----------
This command deletes the value of the $processes variable. The $processes variable still exists, but the value is null.