PowerShell Logo Small

Clear-Item



This is the built-in help made by Microsoft for the command 'Clear-Item', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Deletes the contents of an item, but does not delete the item.

SYNTAX


Clear-Item [-LiteralPath] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Confi
rm] [-WhatIf] [-UseTransaction] [<CommonParameters>]
Clear-Item [-Path] <string[]> [-Credential <PSCredential>] [-Exclude <string[]>] [-Filter <string>] [-Force] [-Include <string[]>] [-Confirm] [-W
hatIf] [-UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Clear-Item cmdlet deletes the value of an item, but it does not delete the item. For example, Clear-Item can delete the value of a variable,
but it does not delete the variable. The value that used to represent a cleared item is defined by each Windows PowerShell provider. Clear-Item
is similar to Clear-Content, but it works on aliases and variables, instead of files.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113283
about_Providers
Copy-Item
Get-Item
Invoke-Item
Move-Item
Set-Item
New-Item
Remove-Item
Rename-Item

REMARKS

<

Examples


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

C:\PS>clear-item Variable:TestVar1



Description
-----------
This command deletes the value of the variable, Testvar1. The variable remains and is valid, but its value is set to null.

The variable name is prefixed with "Variable:" to indicate the Windows PowerShell Variable provider. To get the same result, you can switch to th
e Windows PowerShell Variable provider namespace first and then perform the Clear-Item command.

PS C:> Set-location Variable:
PS Variable:\> clear-item Testvar1








-------------------------- EXAMPLE 2 --------------------------

C:\PS>clear-item Alias:log* -include *1* -exclude *3* -whatif

What if: Performing operation "Clear Item" on Target "Item: log1".



Description
-----------
This command asks Windows PowerShell what would happen if you executed the command, "clear-item alias:log* -include *1* -exclude *3". In response
, Windows PowerShell explains that it would delete the value of the log1 alias.

This command would not have any effect on the log, log2, or log13 aliases. Because the Alias provider does not permit an alias without a value, w
hen you clear an alias, you also delete the alias.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>clear-item registry::HKLM\Software\MyCompany\MyKey -confirm



Description
-----------
This command deletes all registry entries in the MyKey subkey, but only after prompting you to confirm your intent. It does not delete the MyKey
subkey or affect any other registry keys or entries. You can use the Include and Exclude parameters to identify particular registry keys, but you
cannot use them to identify registry entries. To delete particular registry entries, use Remove-ItemProperty. To delete the value of a registry
entry, use Clear-ItemProperty.