Clear-Variable - PowerShell command help and examples

Deletes the value of a variable. (Clear-Variable)


NAME
Clear-Variable
SYNOPSIS
Deletes the value of a variable.
SYNTAX
Clear-Variable [-Name] <string[]> [-Exclude <string[]>] [-Force] [-Include <string[]>] [-PassThru] [-Scope <string>] [-Confirm] [-WhatIf] [<CommonParameters>]
DESCRIPTION
The Clear-Variable cmdlet deletes the data stored in a variable, but it does not delete the variable. As a result, the value of the variable is NULL (empty). If the variable has a specified data or object type, Clear-Variable preserves the type of the object stored in the variable.
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. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Force [<SwitchParameter>] Allows the cmdlet to clear a variable even if it is read-only. Even using the Force parameter, the cmdlet cannot clear constants. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Include <string[]> Clears 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? false -Name <string[]> Specifies the name of the variable to be cleared. Wildcards are permitted. This parameter is required, but the parameter name ("Name") is optional. Required? true Position? 1 Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -PassThru [<SwitchParameter>] Returns an object representing the cleared variable. By default, this cmdlet does not generate any output. Required? false Position? named Default value Accept pipeline input? false 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. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -Confirm [<SwitchParameter>] Prompts you for confirmation before executing the command. Required? false Position? named Default value Accept pipeline input? false Accept wildcard characters? false -WhatIf [<SwitchParameter>] 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 <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, "get-help about_commonparameters".
INPUTS
None You cannot pipe objects to Clear-Variable.
OUTPUTS
None or System.Management.Automation.PSVariable When you use the PassThru parameter, Clear-Variable generates a System.Management.Automation.PSVariable object representing the cleared variable. Otherwise, this cmdlet does not generate any output.
NOTES
To delete a variable, along with its value, use Remove-Variable or Remove-Item. Clear-Variable will not delete the values of variables that are set as constants or owned by the system, even if you use the -Force parameter. If the variable that you are clearing does not exist, the cmdlet has no effect. It does not create a variable with a null value. You can also refer to Clear-Variable by its built-in alias, "clv". For more information, see about_Aliases.

Examples

EXAMPLE 1
C:\PS>clear-variable my* -global
Description
----------- This command deletes the value of the global variables that begin with "my".
EXAMPLE 2
C:\PS>$a=3 C:\PS>&{ clear-variable a } C:\PS>$a 3
Description
----------- These commands demonstrate that clearing a variable in a child scope does not clear the value in the parent scope. The first command sets the value of the variable $a to "3". The second command uses the invoke operator (&) to run a Clear-Variable command in a new scope. The variable is cleared in the child scope (although it did not exist), but it is not cleared in the local scope. The third command, which gets the value of $a, shows that the value "3" is unaffected.
EXAMPLE 3
C:\PS>clear-variable -name processes
Description
----------- This command deletes the value of the $processes variable. The $processes variable still exists, but the value is null. RELATED LINKS Online version: http://go.microsoft.com/fwlink/?LinkID=113285 Get-Variable Set-Variable New-Variable Remove-Variable C:\Windows>powershell get-help Export-Clixml -full

Microsoft Windows [Version 10.0.19045.3693]
Copyright (c) 2023 Microsoft Corporation.

ColorConsole [Version 3.7.1000] PowerShell 2.0-Export

Windows 11, 10, 8.1, 8, 7 / Server 2022, 2019, 2016











Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



PowerShell: Deletes the value of a variable.

HTTP: ... PS_Windows/en/Clear-Variable.htm
0.124
12478
Baumansicht automatisch Ordner aufklappen in Windows 11/10!
Scann und Qualität in Win Scann 2 PDF!
What is an admin mode on Windows 11, 10, ...!
Switch to bold font on Windows-10, -11, and -12 system-wide, but how to?
Windows 10/11 the advanced management of hard drives and drives!
Difference between Notepad and WordPad Windows 11, 10, 8.1 + Server!
Wie kann ich verwenden den Brightness.Manager.OK!
Hilfe TELNET Clients fehlt unter Windows 11, 10. 8.1, 7... warum?
Windows is being prepared - depends on Windows 10 / 11 reboot?
Warum kann ich nicht auf das neue Windows 10 updaten?



(0)