Export (0) Print
Expand All
Expand Minimize

Remove-Variable

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Remove-Variable

Deletes a variable and its value.

Aliases

The following abbreviations are aliases for this cmdlet:

  • rv

Syntax

Parameter Set: Default
Remove-Variable [-Name] <String[]> [-Exclude <String[]> ] [-Force] [-Include <String[]> ] [-Scope <String> ] [-Confirm] [-WhatIf] [ <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 session. You cannot use this cmdlet to delete variables that are set as constants or those that are owned by the system.

Parameters

-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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Force

Allows the cmdlet to remove a variable even if it is read-only. Even using the Force parameter, the cmdlet cannot remove a constant.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Name<String[]>

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


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-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, see about_Scopes.


Aliases

none

Required?

false

Position?

named

Default Value

Local

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.PSVariable

    You can pipe a variable object to Remove-Variable.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None

    This cmdlet does not return any output.


Notes

  • Changes affect only the current scope, such as a session. To delete a variable from all sessions, add a Remove-Variable command to your Windows PowerShell profile.

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

Examples

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

This command deletes the $Smp variable.


PS C:\> remove-variable Smp

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft