PowerShell Logo Small

Clear-Variable



This is the built-in help made by Microsoft for the command 'Clear-Variable', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' 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[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore |
Suspend}] [-InformationVariable [<System.String]>]] [-PassThru] [-Scope [<String>]] [-Confirm] [-WhatIf] [<CommonParameters>]



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 NULL (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/p/?linkid=293944
Get-Variable
New-Variable
Remove-Variable
Set-Variable

REMARKS

<

Examples


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

PS C:\>Clear-Variable my* -Scope Global



This command deletes the value of global variables that have names that begin with "my".










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

PS C:\>$a=3
PS C:\>&{ Clear-Variable a }
PS C:\>$a
3



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 value 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 cleared 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, shows that the value "3" is unaffected.










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

PS C:\>Clear-variable -Name Processes



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