NAME
Remove-Variable
SYNOPSIS
Deletes a variable and its value.SYNTAX
Remove-Variable [-Name]
[-Confirm] [-Exclude ] [-Force] [-Include ] [-Scope
] [-WhatIf] [ ] 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
-Confirm [
Prompts you for confirmation before running the cmdlet. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false] -Exclude
Specifies an array of items that this cmdlet omits from the operation. The value of this parameter qualifiesthe Name parameter. Enter a name element or pattern, such as "s*". Wildcards are permitted.
Required? false Position? named Default value None Accept pipeline input? False Accept wildcard characters? false-Force [
] Indicates that the cmdlet removes a variable even if it is read-only. Even using the Force parameter, the
cmdlet cannot remove a constant. Required? false Position? named Default value False Accept pipeline input? False Accept wildcard characters? false-Include
Specifies an array of items that this cmdlet deletes in the operation. The value of this parameter qualifiesthe Name parameter. Enter a name element or pattern, such as s*. Wildcards are permitted.
Required? false Position? named Default value None Accept pipeline input? False Accept wildcard characters? false-Name
Specifies the name of the variable to be removed. The parameter name ( Name ) is optional.
Required? true Position? 0 Default value NoneAccept pipeline input? True (ByPropertyName)
Accept wildcard characters? false-Scope
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. For more information, see about_Scopes. Required? false Position? named Default value None 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] This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216). INPUTS
System.Management.Automation.PSVariableYou can pipe a variable object to Remove-Variable .
OUTPUTS
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 aRemove-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.
*
Example 1: Remove a variable
PS C:\>Remove-Variable Smp
This command deletes the $Smp variable.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821852Clear-Variable
Get-Variable
New-Variable
Set-Variable