Remove-Variable

 

SYNOPSIS

Deletes a variable and its value.

 

SYNTAX

Remove-Variable [-name] <string[]> [-include <string[]>] [-exclude <string[]>] [-scope <string>] [-force] [-whatIf] [-confirm] [<CommonParameters>]

 

DETAILED DESCRIPTION

The Remove-Variable cmdlet deletes a variable and its value from the scope in which it is defined, such as the current console. You cannot use this cmdlet to delete variables that are set as constants or those that are owned by the system. Changes to the console affect only the current console, unless you use Export-Consoleto save the console.

 

PARAMETERS

 

-name <string[]>

Specifies the name of the variable to be removed. The parameter name ("-Name") is optional.

 

Required?

true

Position?

1

Default value

N/A - The Name must be specified

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

true

 

-include <string[]>

Deletes only the specified items. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-exclude <string[]>

Omits the specified items. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-scope <string>

Specifies the scope in which this alias is valid. Valid values are "Global", "Local", or "Script", or a number relative to the current scope (0 through the number of scopes, where 0 is the current scope and 1 is its parent). "Local" is the default. For more information, type "get-help about_scope".

 

Required?

false

Position?

named

Default value

Local

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-whatIf

Describes what would happen if you executed the command without actually executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-confirm

Prompts you for confirmation before executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Object

 

RETURN TYPE

none

 

NOTES

 

For more information, type "Get-Help Remove-Variable -detailed". For technical information, type "Get-Help Remove-Variable -full".

 

 When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

You can also refer to RemoveVariable by its built-in alias, "rv". For more information, see About_Alias.

 

EXAMPLE 1

 

remove-variable Smp

 

Remove an existing variable $Smp

 

RELATED LINKS

Set-Variable

Get-Variable

Clear-Variable

New-Variable