Remove-Variable

Delete a variable and its value.

Syntax
      Remove-Variable [[-Name] String[] ]
         [-Include string] [-Exclude string] 
            [-scope string] [-force] [-whatIf]
               [-confirm] [CommonParameters]
Key
   -Name 
       The name of the variable(s) to be removed.

   -include string
       Delete only the specified items.
       Wildcards are permitted.
       Qualifies the -Name parameter.

   -Exclude string
       Omit the specified items. Wildcards are permitted.
       Qualifies the -Name parameter.

   -Scope string
       The scope in which this alias is valid. 
       Valid values are "Global", "Local", "Private" 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, type "get-help about_scopes".

   -Force
       Override restrictions that prevent the command from succeeding, apart
       from security settings. e.g. -force will override a files read-only
       attribute, but will not remove a constant.

   -WhatIf
       Describe what would happen if you executed the command without
       actually executing the command.

   -Confirm
       Prompt for confirmation before executing the command.

Standard Aliases for Remove-Variable: rv

Remove-Variable deletes a variable and its value from the scope in which it is defined, such as the current session.
This cmdlet cannot delete variables that are set as constants or those that are owned by the system.

Examples

Remove an existing variable $myvar:

PS C:\> remove-variable myvar

"If any question why we died, Tell them, because our fathers lied" ~ Rudyard Kipling

Related PowerShell Cmdlets

Clear-Variable - Remove the value from a variable.
Get-Variable - Get a PowerShell variable.
New-Variable - Create a new variable.
Set-Variable - Set a variable and a value.
Environment Variables
Equivalent bash command: unset - Remove variable or function names.


 
Copyright © 1999-2024 SS64.com
Some rights reserved