Remove-Variable
Remove-Variable [-Name*] <String[]> [-Confirm] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-Scope<String>] [-WhatIf] [<CommonParameters>]
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
-Confirm [<SwitchParameter>]
- Default value is False
- Accepts pipeline input False
Prompts you for confirmation before running the cmdlet.
-Exclude <String[]>
- Default value is None
- Accepts pipeline input False
Specifies an array of items that this cmdlet omits from the operation. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.
-Force [<SwitchParameter>]
- Default value is False
- Accepts pipeline input False
Indicates that the cmdlet removes a variable even if it is read-only. Even using the Force parameter, the cmdlet cannot remove a constant.
-Include <String[]>
- Default value is None
- Accepts pipeline input False
Specifies an array of items that this cmdlet deletes in the operation. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as s*. Wildcards are permitted.
-Name <String[]>
- This value is required
- Default value is None
- Accepts pipeline input ByPropertyName
Specifies the name of the variable to be removed. The parameter name ( Name ) is optional.
-Scope <String>
- Default value is None
- Accepts pipeline input False
Gets only the variables in the specified scope. The acceptable values for this parameter are:
- Global
- Local
- Script
- 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.
-WhatIf [<SwitchParameter>]
- Default value is False
- Accepts pipeline input False
Shows what would happen if the cmdlet runs. The cmdlet is not run.
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.
Inputs
System.Management.Automation.PSVariableOutputs
NoneExamples
-
Remove a variable:
PS C:\> Remove-Variable Smp
This command deletes the $Smp variable.
Additional 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 Remove-Variable by its built-in alias, rv . For more information, see about_Aliases. *
This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.
PowerShell Commands